답안 #103288

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103288 2019-03-29T15:09:13 Z LittleFlowers__ Examination (JOI19_examination) C++14
100 / 100
1901 ms 66460 KB
#include <bits/stdc++.h>
using namespace std;
const int SZ=1<<10;
int ptr=SZ;
char buffer[SZ];
inline char readchar(){if(ptr==SZ){fread(buffer,1,SZ,stdin); ptr=0;}return buffer[ptr++];}
#define in ({int x=0;int c=readchar(),n=0;for(;!isdigit(c);c=readchar()) n=(c=='-');for(;isdigit(c);c=readchar()) x=x*10+c-'0';n?-x:x;})
inline void out(int 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 "EXAMiNATION"
#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)))

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N=100010;

int n,q;
struct tp{int x,y,z,i;}a[N],t[N];

int ans[N];
vector<int> val;


struct CTDL{
    ordered_set st; int sz=0;
    void add(int x){
        st.insert({x,++sz});
    }
    int get(int x){
        return st.size()-st.order_of_key({x,0});
    }
}T[N];


void upd(int i,int x){
    for(;i;i-=i&-i) T[i].add(x);
}
int que(int i,int x){
    i=lower_bound(all(val),i)-val.begin()+1;
    int ret=0;
    for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
    return ret;
}

signed main(){
    n=in,q=in;
    forinc(i,1,n){
        int x=in,y=in; a[i]={x,y+1,x+y}; val.pb(x);
    }
    forinc(i,1,q) t[i]={in,in+1,in,i};

    sort(all(val)); val.erase(unique(all(val)),val.end());
    forinc(i,1,n) a[i].x=lower_bound(all(val),a[i].x)-val.begin()+1;

    sort(a+1,a+n+1,[](tp i, tp j){return i.z>j.z;});
    sort(t+1,t+q+1,[](tp i, tp j){return i.z>j.z;});

    int j=1;
    forinc(i,1,q){
        while(j<=n && a[j].z>=t[i].z){
            upd(a[j].x,a[j].y); j++;
        }
        ans[t[i].i]=que(t[i].x,t[i].y);
    }
    forinc(i,1,q) out(ans[i]),putchar('\n');
}

Compilation message

examination.cpp: In function 'int que(int, int)':
examination.cpp:56:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(;i<=val.size();i+=i&-i) ret+=T[i].get(x);
          ~^~~~~~~~~~~~
examination.cpp: In function 'char readchar()':
examination.cpp:6:41: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
 inline char readchar(){if(ptr==SZ){fread(buffer,1,SZ,stdin); ptr=0;}return buffer[ptr++];}
                                    ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 10496 KB Output is correct
2 Correct 18 ms 10496 KB Output is correct
3 Correct 19 ms 10496 KB Output is correct
4 Correct 19 ms 10496 KB Output is correct
5 Correct 15 ms 10496 KB Output is correct
6 Correct 18 ms 10496 KB Output is correct
7 Correct 25 ms 11768 KB Output is correct
8 Correct 26 ms 11748 KB Output is correct
9 Correct 27 ms 11776 KB Output is correct
10 Correct 25 ms 11776 KB Output is correct
11 Correct 21 ms 11120 KB Output is correct
12 Correct 30 ms 11128 KB Output is correct
13 Correct 37 ms 11768 KB Output is correct
14 Correct 29 ms 11776 KB Output is correct
15 Correct 23 ms 11776 KB Output is correct
16 Correct 24 ms 10932 KB Output is correct
17 Correct 26 ms 11776 KB Output is correct
18 Correct 28 ms 11000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1845 ms 64760 KB Output is correct
2 Correct 1807 ms 64792 KB Output is correct
3 Correct 1770 ms 64752 KB Output is correct
4 Correct 1299 ms 64624 KB Output is correct
5 Correct 307 ms 26480 KB Output is correct
6 Correct 235 ms 26480 KB Output is correct
7 Correct 1629 ms 64752 KB Output is correct
8 Correct 1620 ms 64668 KB Output is correct
9 Correct 1321 ms 64756 KB Output is correct
10 Correct 101 ms 21104 KB Output is correct
11 Correct 889 ms 64548 KB Output is correct
12 Correct 101 ms 21108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1845 ms 64760 KB Output is correct
2 Correct 1807 ms 64792 KB Output is correct
3 Correct 1770 ms 64752 KB Output is correct
4 Correct 1299 ms 64624 KB Output is correct
5 Correct 307 ms 26480 KB Output is correct
6 Correct 235 ms 26480 KB Output is correct
7 Correct 1629 ms 64752 KB Output is correct
8 Correct 1620 ms 64668 KB Output is correct
9 Correct 1321 ms 64756 KB Output is correct
10 Correct 101 ms 21104 KB Output is correct
11 Correct 889 ms 64548 KB Output is correct
12 Correct 101 ms 21108 KB Output is correct
13 Correct 1520 ms 64836 KB Output is correct
14 Correct 1858 ms 64904 KB Output is correct
15 Correct 1870 ms 64796 KB Output is correct
16 Correct 865 ms 64880 KB Output is correct
17 Correct 253 ms 26736 KB Output is correct
18 Correct 200 ms 26608 KB Output is correct
19 Correct 1512 ms 64816 KB Output is correct
20 Correct 1704 ms 64808 KB Output is correct
21 Correct 1267 ms 64864 KB Output is correct
22 Correct 127 ms 21232 KB Output is correct
23 Correct 812 ms 64684 KB Output is correct
24 Correct 113 ms 21168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 10496 KB Output is correct
2 Correct 18 ms 10496 KB Output is correct
3 Correct 19 ms 10496 KB Output is correct
4 Correct 19 ms 10496 KB Output is correct
5 Correct 15 ms 10496 KB Output is correct
6 Correct 18 ms 10496 KB Output is correct
7 Correct 25 ms 11768 KB Output is correct
8 Correct 26 ms 11748 KB Output is correct
9 Correct 27 ms 11776 KB Output is correct
10 Correct 25 ms 11776 KB Output is correct
11 Correct 21 ms 11120 KB Output is correct
12 Correct 30 ms 11128 KB Output is correct
13 Correct 37 ms 11768 KB Output is correct
14 Correct 29 ms 11776 KB Output is correct
15 Correct 23 ms 11776 KB Output is correct
16 Correct 24 ms 10932 KB Output is correct
17 Correct 26 ms 11776 KB Output is correct
18 Correct 28 ms 11000 KB Output is correct
19 Correct 1845 ms 64760 KB Output is correct
20 Correct 1807 ms 64792 KB Output is correct
21 Correct 1770 ms 64752 KB Output is correct
22 Correct 1299 ms 64624 KB Output is correct
23 Correct 307 ms 26480 KB Output is correct
24 Correct 235 ms 26480 KB Output is correct
25 Correct 1629 ms 64752 KB Output is correct
26 Correct 1620 ms 64668 KB Output is correct
27 Correct 1321 ms 64756 KB Output is correct
28 Correct 101 ms 21104 KB Output is correct
29 Correct 889 ms 64548 KB Output is correct
30 Correct 101 ms 21108 KB Output is correct
31 Correct 1520 ms 64836 KB Output is correct
32 Correct 1858 ms 64904 KB Output is correct
33 Correct 1870 ms 64796 KB Output is correct
34 Correct 865 ms 64880 KB Output is correct
35 Correct 253 ms 26736 KB Output is correct
36 Correct 200 ms 26608 KB Output is correct
37 Correct 1512 ms 64816 KB Output is correct
38 Correct 1704 ms 64808 KB Output is correct
39 Correct 1267 ms 64864 KB Output is correct
40 Correct 127 ms 21232 KB Output is correct
41 Correct 812 ms 64684 KB Output is correct
42 Correct 113 ms 21168 KB Output is correct
43 Correct 1482 ms 66372 KB Output is correct
44 Correct 1434 ms 66460 KB Output is correct
45 Correct 1901 ms 66436 KB Output is correct
46 Correct 875 ms 66416 KB Output is correct
47 Correct 320 ms 26636 KB Output is correct
48 Correct 179 ms 26476 KB Output is correct
49 Correct 1661 ms 66380 KB Output is correct
50 Correct 1376 ms 66416 KB Output is correct
51 Correct 1208 ms 66404 KB Output is correct
52 Correct 179 ms 21292 KB Output is correct
53 Correct 1004 ms 66280 KB Output is correct