125742024-12-23 18:12:194rt3xp02015. decembercpp17Accepted 16ms792 KiB
#include<bits/stdc++.h>
using namespace std;
vector<bool> visible(10001,0);

struct box{
  int x1,y1,x2,y2,id;
};

void f(const vector<box> &v, bool x=false){
  int N=100489,SQRT=317;
  vector<bool> a(N,0),b(SQRT,0); vector<int> sumb(SQRT,0);
  for(const box &box: v){
    int l,r,sum=0;
    if(x){
      l=box.x1; r=box.x2;
    }
    else{
      l=box.y1; r=box.y2;
    }
    r--;
    for(int i=l;i<=r;){
      if(i%SQRT==0 && i+SQRT-1<=r){
        if(!b[i/SQRT]){
          b[i/SQRT]=1;
          visible[box.id]=1;
        }
        i+=SQRT;
      }
      else{
        if(!a[i]){
          a[i]=1; sumb[i/SQRT]++; if(sumb[i/SQRT]==SQRT) b[i/SQRT]=1;
          visible[box.id]=1;
        }
        i++;
      }
    }
  }
}

int main(){
  int n,m,k,id=0,cnt=0; cin >> n >> m >> k;
  vector<box> v(k);
  for(box &i: v){
    cin >> i.x1 >> i.y1 >> i.x2 >> i.y2;
    i.id=++id;
  }
  sort(v.begin(),v.end(),[](const box &l, const box &r){return l.x1<r.x1;}); f(v);
  sort(v.begin(),v.end(),[](const box &l, const box &r){return l.x2>r.x2;}); f(v);
  sort(v.begin(),v.end(),[](const box &l, const box &r){return l.y1<r.y1;}); f(v,true);
  sort(v.begin(),v.end(),[](const box &l, const box &r){return l.y2>r.y2;}); f(v,true);
  // for(int i=1;i<=k;i++) if(!visible[i]) cout << i << '\n';
  for(int i=1;i<=k;i++) if(!visible[i]) cnt++;
  cout << cnt;
}
1 - Accepted
Memory: 320KiB
Time: 1ms

Program's output:
3
Expected output:
3
Checker output:
ok 1 number(s): "3"

2 - Accepted
Memory: 568KiB
Time: 9ms

Program's output:
11
Expected output:
11
Checker output:
ok 1 number(s): "11"

3 - Accepted
Memory: 320KiB
Time: 4ms

Program's output:
3
Expected output:
3
Checker output:
ok 1 number(s): "3"

4 - Accepted
Memory: 320KiB
Time: 2ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

5 - Accepted
Memory: 748KiB
Time: 14ms

Program's output:
62
Expected output:
62
Checker output:
ok 1 number(s): "62"

6 - Accepted
Memory: 568KiB
Time: 9ms

Program's output:
174
Expected output:
174
Checker output:
ok 1 number(s): "174"

7 - Accepted
Memory: 320KiB
Time: 4ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

8 - Accepted
Memory: 348KiB
Time: 3ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

9 - Accepted
Memory: 724KiB
Time: 13ms

Program's output:
4
Expected output:
4
Checker output:
ok 1 number(s): "4"

10 - Accepted
Memory: 568KiB
Time: 8ms

Program's output:
569
Expected output:
569
Checker output:
ok 1 number(s): "569"

11 - Accepted
Memory: 568KiB
Time: 7ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

12 - Accepted
Memory: 668KiB
Time: 10ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

13 - Accepted
Memory: 568KiB
Time: 8ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

14 - Accepted
Memory: 568KiB
Time: 7ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

15 - Accepted
Memory: 568KiB
Time: 8ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

16 - Accepted
Memory: 568KiB
Time: 12ms

Program's output:
14
Expected output:
14
Checker output:
ok 1 number(s): "14"

17 - Accepted
Memory: 580KiB
Time: 7ms

Program's output:
1
Expected output:
1
Checker output:
ok 1 number(s): "1"

18 - Accepted
Memory: 568KiB
Time: 10ms

Program's output:
6
Expected output:
6
Checker output:
ok 1 number(s): "6"

19 - Accepted
Memory: 572KiB
Time: 12ms

Program's output:
8
Expected output:
8
Checker output:
ok 1 number(s): "8"

20 - Accepted
Memory: 688KiB
Time: 4ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

21 - Accepted
Memory: 420KiB
Time: 6ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"

22 - Accepted
Memory: 792KiB
Time: 16ms

Program's output:
2
Expected output:
2
Checker output:
ok 1 number(s): "2"

23 - Accepted
Memory: 320KiB
Time: 3ms

Program's output:
0
Expected output:
0
Checker output:
ok 1 number(s): "0"