Submission #331426

# Submission time Handle Problem Language Result Execution time Memory
331426 2020-11-28T12:56:10 Z EIMONIM Examination (JOI19_examination) C++14
100 / 100
1115 ms 17972 KB
#include <bits/stdc++.h>
#define loop(i,s,e) for(int i=s;i<e;i++)
#define loopr(i,s,e) for(int i=e-1;i>=s;i--)
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;

int MAXX = 0, MAXY = 0;
struct Node{
    int v=0;
    Node *lp=0, *rp=0;
    Node(){}
    void fix(){
        if (!lp) lp = new Node();
        if (!rp) rp = new Node();
    }
    void update(int i, int dx, int l, int r){
        if (r<=l) return ;
        if (l+1==r){
            v+=dx;
            return ;
        }
        int mid = (l+r)/2;
        fix();
        if (i<mid) lp->update(i,dx,l,mid);
        else rp->update(i,dx,mid,r);
        //cout<<"UPDATE1: "<<i<<" "<<l<<" "<<r<<(v - lp->v - rp->v)<<endl;
        v = lp->v + rp->v;
    }
    int query(int a, int b, int l, int r){
        if (a>r || b<l) return 0;
        //cout<<"QUERY1: "<<a<<" "<<v<<" "<<l<<" "<<r<<endl;
        if (a<=l && r<=b) return v;
        int res = 0, mid = (l+r)/2;
        if (lp) res += lp->query(a,b,l,mid);
        if (rp) res += rp->query(a,b,mid,r);
        return res;
    }
};
struct SEG{
    int n, sz;
    vector<int> a;
    SEG(int n=0): n(n){
        for(sz=1;sz<n;sz*=2);
        a.resize(2*sz);
    }
    void update(int i, int dx){
        a[i+=sz]+=dx;
        for(i/=2;i;i/=2) a[i] = a[2*i] + a[2*i+1];
    }
    int query(int l, int r){
        int res = 0;
        for(l+=sz, r+=sz; l<=r; l/=2, r/=2){
            if (l%2) res += a[l++];
            if (r%2==0) res += a[r--];
        }
        return res;
    }
};

bool cmp(pair<int, int> a, pair<int, int> b){
    return (a.first==b.first?a.second<b.second:a.first>b.first);
}
const int MAXN = 1e5 + 10;
int n,q;
int s[MAXN], t[MAXN];
int a[MAXN], b[MAXN], c[MAXN];
int ans[MAXN];
pair<int, int> vals[2*MAXN];

SEG seg;
void solve(int l, int r){
    if (r<=l+1) return ;
    int mid = (l+r)/2;
    //cout<<"HI: "<<l<<" "<<r<<endl;
    solve(l, mid);
    solve(mid, r);
    vector<pair<int, int>> eve;
    loop(i,l,mid) {
        int ind = vals[i].second;
        if(ind<n) eve.push_back({s[ind], ind});
    }
    loop(i,mid,r) {
        int ind = vals[i].second;
        if(ind>=n) eve.push_back({a[ind-n], ind});
    }
    sort(eve.begin(), eve.end());
    for(auto &e:eve){
        int i = e.second;
        if (i<n){
            seg.update(t[i], 1);
        }
        else{
            ans[i-n]+=seg.query(0, b[i-n]);
        }
    }
    for(auto &e:eve){
        int i = e.second;
        if (i<n){
            seg.update(t[i], -1);
        }
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>q;
    map<int, int> convs, convt;
    loop(i,0,n){
        cin>>s[i]>>t[i];
        vals[i] = {s[i]+t[i], i};
        convs[s[i]];
        convt[t[i]];
        //MAXX = max(MAXX, s[i]);
        //MAXY = max(MAXY, t[i]);
    }
    loop(i,0,q){
        cin>>a[i]>>b[i]>>c[i];
        vals[i+n] = {c[i], n+i};
        //MAXX = max(MAXX, a[i]);
        //MAXY = max(MAXY, b[i]);
    }
    convs[INF] = convt[INF];
    sort(vals, vals+n+q, cmp);
    //MAXX++, MAXY++;
    int cnt = 0;
    for(auto &p:convs) p.second = cnt++;
    for(auto &p:convs) p.second = cnt - p.second-1;
    MAXX = cnt, cnt = 0;
    for(auto &p:convt) p.second = cnt++;
    for(auto &p:convt) p.second = cnt - p.second-1;
    MAXY = cnt;
    loop(i,0,n) s[i] = convs[s[i]], t[i] = convt[t[i]];
    loop(i,0,q) a[i] = convs.lower_bound(a[i])->second, b[i] = convt.lower_bound(b[i])->second;
    seg = SEG(MAXY);
    //sparsebit bit;
    solve(0, n+q);
    /*loop(ind, 0, n+q){
        int i = vals[ind].second;
        //cout<<"VALS: "<<vals[ind].first<<" "<<i<<" "<<i-n<<endl;
        if (i<n){ // point
            seg.update(s[i], t[i], 1, 0, MAXX);
            //bit.add(s[i], t[i]);
        }
        else{ // query
            i-=n;
            ans[i] = seg.query(0, a[i]+1, 0, b[i]+1, 0, MAXX);
            //ans[i] = bit.qry(a[i], b[i]);
        }
    }*/
    loop(i,0,q) cout<<ans[i]<<endl;
    return 0;
}
/*
color a
cls
g++ Examination.cpp -o a & a
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100





*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 18 ms 876 KB Output is correct
8 Correct 18 ms 896 KB Output is correct
9 Correct 18 ms 876 KB Output is correct
10 Correct 14 ms 748 KB Output is correct
11 Correct 17 ms 748 KB Output is correct
12 Correct 13 ms 620 KB Output is correct
13 Correct 18 ms 876 KB Output is correct
14 Correct 18 ms 876 KB Output is correct
15 Correct 18 ms 896 KB Output is correct
16 Correct 15 ms 748 KB Output is correct
17 Correct 13 ms 748 KB Output is correct
18 Correct 11 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 935 ms 12944 KB Output is correct
2 Correct 901 ms 13072 KB Output is correct
3 Correct 855 ms 13016 KB Output is correct
4 Correct 551 ms 9348 KB Output is correct
5 Correct 706 ms 10028 KB Output is correct
6 Correct 490 ms 6408 KB Output is correct
7 Correct 879 ms 12928 KB Output is correct
8 Correct 869 ms 12924 KB Output is correct
9 Correct 850 ms 12948 KB Output is correct
10 Correct 677 ms 9884 KB Output is correct
11 Correct 512 ms 9500 KB Output is correct
12 Correct 388 ms 6536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 935 ms 12944 KB Output is correct
2 Correct 901 ms 13072 KB Output is correct
3 Correct 855 ms 13016 KB Output is correct
4 Correct 551 ms 9348 KB Output is correct
5 Correct 706 ms 10028 KB Output is correct
6 Correct 490 ms 6408 KB Output is correct
7 Correct 879 ms 12928 KB Output is correct
8 Correct 869 ms 12924 KB Output is correct
9 Correct 850 ms 12948 KB Output is correct
10 Correct 677 ms 9884 KB Output is correct
11 Correct 512 ms 9500 KB Output is correct
12 Correct 388 ms 6536 KB Output is correct
13 Correct 943 ms 12244 KB Output is correct
14 Correct 961 ms 13892 KB Output is correct
15 Correct 894 ms 13008 KB Output is correct
16 Correct 584 ms 8852 KB Output is correct
17 Correct 759 ms 9672 KB Output is correct
18 Correct 501 ms 7444 KB Output is correct
19 Correct 935 ms 12520 KB Output is correct
20 Correct 965 ms 12480 KB Output is correct
21 Correct 916 ms 12588 KB Output is correct
22 Correct 674 ms 10028 KB Output is correct
23 Correct 505 ms 9368 KB Output is correct
24 Correct 374 ms 6408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 18 ms 876 KB Output is correct
8 Correct 18 ms 896 KB Output is correct
9 Correct 18 ms 876 KB Output is correct
10 Correct 14 ms 748 KB Output is correct
11 Correct 17 ms 748 KB Output is correct
12 Correct 13 ms 620 KB Output is correct
13 Correct 18 ms 876 KB Output is correct
14 Correct 18 ms 876 KB Output is correct
15 Correct 18 ms 896 KB Output is correct
16 Correct 15 ms 748 KB Output is correct
17 Correct 13 ms 748 KB Output is correct
18 Correct 11 ms 492 KB Output is correct
19 Correct 935 ms 12944 KB Output is correct
20 Correct 901 ms 13072 KB Output is correct
21 Correct 855 ms 13016 KB Output is correct
22 Correct 551 ms 9348 KB Output is correct
23 Correct 706 ms 10028 KB Output is correct
24 Correct 490 ms 6408 KB Output is correct
25 Correct 879 ms 12928 KB Output is correct
26 Correct 869 ms 12924 KB Output is correct
27 Correct 850 ms 12948 KB Output is correct
28 Correct 677 ms 9884 KB Output is correct
29 Correct 512 ms 9500 KB Output is correct
30 Correct 388 ms 6536 KB Output is correct
31 Correct 943 ms 12244 KB Output is correct
32 Correct 961 ms 13892 KB Output is correct
33 Correct 894 ms 13008 KB Output is correct
34 Correct 584 ms 8852 KB Output is correct
35 Correct 759 ms 9672 KB Output is correct
36 Correct 501 ms 7444 KB Output is correct
37 Correct 935 ms 12520 KB Output is correct
38 Correct 965 ms 12480 KB Output is correct
39 Correct 916 ms 12588 KB Output is correct
40 Correct 674 ms 10028 KB Output is correct
41 Correct 505 ms 9368 KB Output is correct
42 Correct 374 ms 6408 KB Output is correct
43 Correct 1058 ms 16240 KB Output is correct
44 Correct 1070 ms 16212 KB Output is correct
45 Correct 1115 ms 17840 KB Output is correct
46 Correct 618 ms 10532 KB Output is correct
47 Correct 809 ms 11668 KB Output is correct
48 Correct 482 ms 5176 KB Output is correct
49 Correct 1047 ms 17972 KB Output is correct
50 Correct 1018 ms 16376 KB Output is correct
51 Correct 1031 ms 17968 KB Output is correct
52 Correct 789 ms 11552 KB Output is correct
53 Correct 545 ms 11156 KB Output is correct