답안 #103546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103546 2019-03-31T11:48:00 Z LittleFlowers__ Examination (JOI19_examination) C++14
100 / 100
638 ms 22864 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define task "exam"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=100010;
int n,m;
int ans[N];
struct id{
    int x,y,z,i;
}a[N],q[N];
vector<int> rr;
vector<int> bit[N],val[N];

int upp(const vector<int>&x,int y){
    return lower_bound(all(x),y)-x.begin()+1;
}

void add(int x,int y){
    int i=upp(rr,x);
    for(;i;i-=i&-i) val[i].pb(y);
}
void upd(int x,int y){
    int i=upp(rr,x);
    for(;i;i-=i&-i){
        int j=upp(val[i],y);
        for(;j;j-=j&-j) bit[i][j]++;
    }
}
int get(int x,int y){
    int ret=0;
    int i=upp(rr,x);
    for(;i<=rr.size();i+=i&-i){
        int j=upp(val[i],y);
        for(;j<bit[i].size();j+=j&-j) ret+=bit[i][j];
    }
    return ret;
}
main(){
    n=in,m=in;
    forinc(i,1,n){
        int x=in,y=in,z=x+y;
        a[i]={x,y,z};
        rr.pb(x);
    }
    forinc(i,1,m) q[i]={in,in,in,i};
    sort(all(rr)); rr.erase(unique(all(rr)),rr.end());

    forinc(i,1,n) add(a[i].x,a[i].y);

    forinc(i,1,n) sort(all(val[i])),bit[i].resize(val[i].size()+1);

    sort(a+1,a+n+1,[](id i,id j){return i.z>j.z;});
    sort(q+1,q+m+1,[](id i,id j){return i.z>j.z;});
    int j=1;
    forinc(i,1,m){
        while(j<=n && a[j].z>=q[i].z){
            upd(a[j].x,a[j].y); j++;
        }
        ans[q[i].i]=get(q[i].x,q[i].y);
    }
    forinc(i,1,m) cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp: In function 'int get(int, int)':
examination.cpp:48:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=rr.size();i+=i&-i){
          ~^~~~~~~~~~~
examination.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(;j<bit[i].size();j+=j&-j) ret+=bit[i][j];
              ~^~~~~~~~~~~~~~
examination.cpp: At global scope:
examination.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 17 ms 5632 KB Output is correct
8 Correct 15 ms 5632 KB Output is correct
9 Correct 13 ms 5604 KB Output is correct
10 Correct 12 ms 5504 KB Output is correct
11 Correct 11 ms 5376 KB Output is correct
12 Correct 8 ms 5376 KB Output is correct
13 Correct 12 ms 5504 KB Output is correct
14 Correct 12 ms 5504 KB Output is correct
15 Correct 15 ms 5504 KB Output is correct
16 Correct 10 ms 5376 KB Output is correct
17 Correct 10 ms 5504 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 449 ms 21884 KB Output is correct
2 Correct 462 ms 21312 KB Output is correct
3 Correct 442 ms 21536 KB Output is correct
4 Correct 394 ms 21360 KB Output is correct
5 Correct 129 ms 15540 KB Output is correct
6 Correct 81 ms 15344 KB Output is correct
7 Correct 441 ms 21324 KB Output is correct
8 Correct 459 ms 21740 KB Output is correct
9 Correct 419 ms 21412 KB Output is correct
10 Correct 85 ms 14444 KB Output is correct
11 Correct 300 ms 21232 KB Output is correct
12 Correct 58 ms 14032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 449 ms 21884 KB Output is correct
2 Correct 462 ms 21312 KB Output is correct
3 Correct 442 ms 21536 KB Output is correct
4 Correct 394 ms 21360 KB Output is correct
5 Correct 129 ms 15540 KB Output is correct
6 Correct 81 ms 15344 KB Output is correct
7 Correct 441 ms 21324 KB Output is correct
8 Correct 459 ms 21740 KB Output is correct
9 Correct 419 ms 21412 KB Output is correct
10 Correct 85 ms 14444 KB Output is correct
11 Correct 300 ms 21232 KB Output is correct
12 Correct 58 ms 14032 KB Output is correct
13 Correct 498 ms 21324 KB Output is correct
14 Correct 494 ms 21488 KB Output is correct
15 Correct 480 ms 21360 KB Output is correct
16 Correct 328 ms 21460 KB Output is correct
17 Correct 152 ms 15476 KB Output is correct
18 Correct 75 ms 15336 KB Output is correct
19 Correct 497 ms 21304 KB Output is correct
20 Correct 494 ms 21332 KB Output is correct
21 Correct 526 ms 21616 KB Output is correct
22 Correct 88 ms 14568 KB Output is correct
23 Correct 269 ms 21184 KB Output is correct
24 Correct 44 ms 14064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 17 ms 5632 KB Output is correct
8 Correct 15 ms 5632 KB Output is correct
9 Correct 13 ms 5604 KB Output is correct
10 Correct 12 ms 5504 KB Output is correct
11 Correct 11 ms 5376 KB Output is correct
12 Correct 8 ms 5376 KB Output is correct
13 Correct 12 ms 5504 KB Output is correct
14 Correct 12 ms 5504 KB Output is correct
15 Correct 15 ms 5504 KB Output is correct
16 Correct 10 ms 5376 KB Output is correct
17 Correct 10 ms 5504 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
19 Correct 449 ms 21884 KB Output is correct
20 Correct 462 ms 21312 KB Output is correct
21 Correct 442 ms 21536 KB Output is correct
22 Correct 394 ms 21360 KB Output is correct
23 Correct 129 ms 15540 KB Output is correct
24 Correct 81 ms 15344 KB Output is correct
25 Correct 441 ms 21324 KB Output is correct
26 Correct 459 ms 21740 KB Output is correct
27 Correct 419 ms 21412 KB Output is correct
28 Correct 85 ms 14444 KB Output is correct
29 Correct 300 ms 21232 KB Output is correct
30 Correct 58 ms 14032 KB Output is correct
31 Correct 498 ms 21324 KB Output is correct
32 Correct 494 ms 21488 KB Output is correct
33 Correct 480 ms 21360 KB Output is correct
34 Correct 328 ms 21460 KB Output is correct
35 Correct 152 ms 15476 KB Output is correct
36 Correct 75 ms 15336 KB Output is correct
37 Correct 497 ms 21304 KB Output is correct
38 Correct 494 ms 21332 KB Output is correct
39 Correct 526 ms 21616 KB Output is correct
40 Correct 88 ms 14568 KB Output is correct
41 Correct 269 ms 21184 KB Output is correct
42 Correct 44 ms 14064 KB Output is correct
43 Correct 606 ms 22864 KB Output is correct
44 Correct 598 ms 22736 KB Output is correct
45 Correct 638 ms 22640 KB Output is correct
46 Correct 475 ms 21940 KB Output is correct
47 Correct 134 ms 15444 KB Output is correct
48 Correct 96 ms 15188 KB Output is correct
49 Correct 555 ms 22500 KB Output is correct
50 Correct 569 ms 22548 KB Output is correct
51 Correct 518 ms 22552 KB Output is correct
52 Correct 103 ms 14444 KB Output is correct
53 Correct 371 ms 21876 KB Output is correct