Submission #375205

# Submission time Handle Problem Language Result Execution time Memory
375205 2021-03-09T04:26:21 Z jass921026 Examination (JOI19_examination) C++14
100 / 100
330 ms 17012 KB
#include<bits/stdc++.h>
using namespace std;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ALL(x) (x).begin(),(x).end()
typedef pair<int,int> pii;
#define F first
#define S second
const int MAXN=1E5+10, MAXC=2E5+21;
struct student{
    int type, a, b, c, id;
    student(int t, int a, int b, int c, int id):type(t),a(a),b(b),c(c),id(id){};
};
bool cmp(student x, student y){
    if(x.c==y.c) return x.type<y.type;
    return x.c>y.c;
}
int n, q, ans[MAXN];
vector<int> comp;
vector<student> v;
struct BIT{
    int data[MAXC]={0};
    vector<pii> his;
    int lb(int x){
        return x&(-x);
    }
    void modify(int p, int v, bool u=1){
        if(u) his.push_back({p,v});
        //if(u) cout<<"modified "<<p<<" "<<v<<"\n";
        while(p<MAXC){
            data[p]+=v;
            p+=lb(p);
        }
    }
    int query(int p){
        int res=0;
        while(p>0){
            res+=data[p];
            p-=lb(p);
        }
        return res;
    }
    int query(int l, int r){
        //cout<<"queried "<<l<<" "<<r<<"\n";
        int x=query(r)-query(l-1);
        //cout<<"result: "<<x<<"\n";
        return x;
    }
    void undo(){
        for(auto i:his){
            modify(i.F,-i.S,0);
        }
        his.clear();
    }
} bit;
void CDQORZ(int l, int r){
    if(l==r) return;
    int mid=(l+r)/2;
    CDQORZ(l,mid);
    CDQORZ(mid+1,r);
    vector<student> nv;
    int i=l, j=mid+1;
    //cout<<"now on "<<l<<" "<<r<<"\n";
    while(i<=mid||j<=r){
        //cout<<i<<" "<<j<<"\n";
        if(j==r+1){
            nv.push_back(v[i]);
            if(v[i].type==0) bit.modify(v[i].b,1);
            i++;
        } else if(i==mid+1){
            nv.push_back(v[j]);
            if(v[j].type==1) ans[v[j].id]+=bit.query(v[j].b,MAXC-1);
            j++;
        } else if(v[i].a>=v[j].a){
            nv.push_back(v[i]);
            if(v[i].type==0) bit.modify(v[i].b,1);
            i++;
        } else{
            nv.push_back(v[j]);
            if(v[j].type==1) ans[v[j].id]+=bit.query(v[j].b,MAXC-1);
            j++;
        }
    }
    bit.undo();
    for(int k=0;k<nv.size();k++){
        v[l+k]=nv[k];
    }
}
int main(){ jizz
    cin>>n>>q;
    for(int i=0;i<n;i++){
        int s, t;
        cin>>s>>t;
        v.push_back(student(0,s,t,s+t,i));
        comp.push_back(t);
    }
    for(int i=0;i<q;i++){
        int x, y, z;
        cin>>x>>y>>z;
        v.push_back(student(1,x,y,z,i));
        comp.push_back(y);
    }
    sort(ALL(comp));
    comp.erase(unique(ALL(comp)),comp.end());
    for(int i=0;i<n+q;i++){
        v[i].b=lower_bound(ALL(comp),v[i].b)-comp.begin()+1;
    }
    sort(ALL(v),cmp);
    /*for(int i=0;i<n+q;i++){
        cout<<v[i].type<<" "<<v[i].a<<" "<<v[i].b<<" "<<v[i].c<<" "<<v[i].id<<"\n";
    }*/
    CDQORZ(0,n+q-1);
    for(int i=0;i<q;i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/
/*
10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
*/

Compilation message

examination.cpp: In function 'void CDQORZ(int, int)':
examination.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int k=0;k<nv.size();k++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 8 ms 1616 KB Output is correct
8 Correct 8 ms 1616 KB Output is correct
9 Correct 8 ms 1616 KB Output is correct
10 Correct 7 ms 1624 KB Output is correct
11 Correct 10 ms 1764 KB Output is correct
12 Correct 7 ms 1616 KB Output is correct
13 Correct 8 ms 1764 KB Output is correct
14 Correct 8 ms 1616 KB Output is correct
15 Correct 10 ms 1616 KB Output is correct
16 Correct 9 ms 1784 KB Output is correct
17 Correct 7 ms 1644 KB Output is correct
18 Correct 6 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 15988 KB Output is correct
2 Correct 273 ms 16060 KB Output is correct
3 Correct 279 ms 16116 KB Output is correct
4 Correct 240 ms 15988 KB Output is correct
5 Correct 247 ms 15988 KB Output is correct
6 Correct 220 ms 15988 KB Output is correct
7 Correct 271 ms 15988 KB Output is correct
8 Correct 267 ms 15988 KB Output is correct
9 Correct 262 ms 16008 KB Output is correct
10 Correct 259 ms 15988 KB Output is correct
11 Correct 231 ms 15988 KB Output is correct
12 Correct 237 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 15988 KB Output is correct
2 Correct 273 ms 16060 KB Output is correct
3 Correct 279 ms 16116 KB Output is correct
4 Correct 240 ms 15988 KB Output is correct
5 Correct 247 ms 15988 KB Output is correct
6 Correct 220 ms 15988 KB Output is correct
7 Correct 271 ms 15988 KB Output is correct
8 Correct 267 ms 15988 KB Output is correct
9 Correct 262 ms 16008 KB Output is correct
10 Correct 259 ms 15988 KB Output is correct
11 Correct 231 ms 15988 KB Output is correct
12 Correct 237 ms 15952 KB Output is correct
13 Correct 319 ms 15860 KB Output is correct
14 Correct 319 ms 16116 KB Output is correct
15 Correct 283 ms 16008 KB Output is correct
16 Correct 256 ms 15604 KB Output is correct
17 Correct 277 ms 15988 KB Output is correct
18 Correct 224 ms 15988 KB Output is correct
19 Correct 296 ms 16116 KB Output is correct
20 Correct 303 ms 15736 KB Output is correct
21 Correct 286 ms 15604 KB Output is correct
22 Correct 238 ms 16116 KB Output is correct
23 Correct 226 ms 15988 KB Output is correct
24 Correct 207 ms 15988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 8 ms 1616 KB Output is correct
8 Correct 8 ms 1616 KB Output is correct
9 Correct 8 ms 1616 KB Output is correct
10 Correct 7 ms 1624 KB Output is correct
11 Correct 10 ms 1764 KB Output is correct
12 Correct 7 ms 1616 KB Output is correct
13 Correct 8 ms 1764 KB Output is correct
14 Correct 8 ms 1616 KB Output is correct
15 Correct 10 ms 1616 KB Output is correct
16 Correct 9 ms 1784 KB Output is correct
17 Correct 7 ms 1644 KB Output is correct
18 Correct 6 ms 1616 KB Output is correct
19 Correct 280 ms 15988 KB Output is correct
20 Correct 273 ms 16060 KB Output is correct
21 Correct 279 ms 16116 KB Output is correct
22 Correct 240 ms 15988 KB Output is correct
23 Correct 247 ms 15988 KB Output is correct
24 Correct 220 ms 15988 KB Output is correct
25 Correct 271 ms 15988 KB Output is correct
26 Correct 267 ms 15988 KB Output is correct
27 Correct 262 ms 16008 KB Output is correct
28 Correct 259 ms 15988 KB Output is correct
29 Correct 231 ms 15988 KB Output is correct
30 Correct 237 ms 15952 KB Output is correct
31 Correct 319 ms 15860 KB Output is correct
32 Correct 319 ms 16116 KB Output is correct
33 Correct 283 ms 16008 KB Output is correct
34 Correct 256 ms 15604 KB Output is correct
35 Correct 277 ms 15988 KB Output is correct
36 Correct 224 ms 15988 KB Output is correct
37 Correct 296 ms 16116 KB Output is correct
38 Correct 303 ms 15736 KB Output is correct
39 Correct 286 ms 15604 KB Output is correct
40 Correct 238 ms 16116 KB Output is correct
41 Correct 226 ms 15988 KB Output is correct
42 Correct 207 ms 15988 KB Output is correct
43 Correct 315 ms 15860 KB Output is correct
44 Correct 313 ms 16756 KB Output is correct
45 Correct 317 ms 16756 KB Output is correct
46 Correct 263 ms 16628 KB Output is correct
47 Correct 288 ms 16884 KB Output is correct
48 Correct 221 ms 17012 KB Output is correct
49 Correct 305 ms 16756 KB Output is correct
50 Correct 330 ms 16884 KB Output is correct
51 Correct 300 ms 16756 KB Output is correct
52 Correct 277 ms 16884 KB Output is correct
53 Correct 235 ms 16884 KB Output is correct