Submission #881870

# Submission time Handle Problem Language Result Execution time Memory
881870 2023-12-02T06:30:25 Z dimashhh Examination (JOI19_examination) C++17
100 / 100
292 ms 58132 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 7e5 + 10, MOD = 1e9 + 7;

int n,q,s[N],t[N],x[N],y[N],z[N],sm[N],res[N],X[N],Y[N],Z[N];
vector<int> a,p,qq;
struct segtree{
    int t[N * 4];
    void build(int v = 1,int tl = 1,int tr = N){
        t[v] =0 ;
        if(tl == tr) return;
        int tm = (tl + tr) >> 1;
        build(v + v,tl,tm);
        build(v + v + 1,tm + 1,tr);
    }
    void upd(int pos,int val,int v = 1,int tl = 1,int tr = N){
        if(tl == tr){
            t[v] += val;
        }else{
            int tm = (tl + tr) >> 1;
            if(pos <= tm) upd(pos,val,v+v,tl,tm);
            else upd(pos,val,v+v+1,tm+1,tr);
            t[v] = t[v + v] + t[v + v + 1];
        }
    }
    int get(int l,int r,int v = 1,int tl = 1,int tr = N){
        if(l > r || tl > r || l > tr) return 0;
        if(tl >= l && tr <= r) return t[v];
        int tm = (tl + tr) >> 1;
        return get(l,r,v+v,tl,tm) + get(l,r,v+v+1,tm+1,tr);
    }
}A,B;
int find(int val){
    int it = lower_bound(a.begin(),a.end(),val) - a.begin();
    return it + 1;
}
bool cmp(int i,int j){
    return (sm[i] > sm[j]);
}
bool cmp1(int i,int j){
    return (z[i] > z[j]);
}
bool cmp2(int i,int j){
    return (y[i] > y[j]);
}
bool cmp3(int i,int j){
    return (t[i] > t[j]);
}
void test(){
    A.build();
    B.build();
    cin >> n >> q;
    p.resize(n);
    iota(p.begin(),p.end(),1);
    qq.resize(q);
    iota(qq.begin(),qq.end(),1);
    for(int i = 1;i <= n;i++){
        cin >> s[i] >> t[i];
        sm[i] = s[i] + t[i];
        a.push_back(s[i]);
        a.push_back(t[i]);
        a.push_back(sm[i]);
    }
    for(int i = 1;i <= q;i++){
        cin >> x[i] >> y[i] >> z[i];
        X[i] = x[i];
        Y[i] = y[i];
        Z[i] = z[i];
        a.push_back(x[i]);
        a.push_back(y[i]);
        a.push_back(z[i]);
    }
    sort(a.begin(),a.end());
    for(int i = 1;i <= n;i++){
        s[i] = find(s[i]);t[i] = find(t[i]);sm[i] = find(sm[i]);
    }
    for(int i = 1;i <= q;i++){
        x[i] = find(x[i]);y[i] = find(y[i]);z[i] = find(z[i]);
    }
    sort(p.begin(),p.end(),cmp);
    sort(qq.begin(),qq.end(),cmp1);
    int it = 0;
    vector<pair<int,int>> f;
    vector<int> pos;
    for(int i:qq){
        if(X[i] + Y[i] >= Z[i]){
            pos.push_back(i);
            continue;
        }
        while(it < p.size() && sm[p[it]] >= z[i]){
            A.upd(s[p[it]],1);
            B.upd(t[p[it]],1);
            f.push_back({s[p[it]],t[p[it]]});
            it++;
        }
        int col = 0;
        res[i] = A.get(x[i],N) + B.get(y[i],N) - it;
    }
    A.build();
    it = 0;
    sort(p.begin(),p.end(),cmp3);
    sort(pos.begin(),pos.end(),cmp2);
    vector<int> all;
    for(auto i:pos){

        while(it < n && t[p[it]] >= y[i]){
            A.upd(s[p[it]],1);
            all.push_back(s[p[it]]);
            it++;
        }
        int col = 0;
        // for(auto j:all){
        //     if(j >= x[i]) col++;
        // }
        // res[i] = col;
        // cout << i << ' ' << res[i] << "x\n";
        res[i] = A.get(x[i],N);
    }
    for(int i = 1;i <= q;i++){
        cout << res[i] << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++)
    {
        test();
    }
}

Compilation message

examination.cpp: In function 'void test()':
examination.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         while(it < p.size() && sm[p[it]] >= z[i]){
      |               ~~~^~~~~~~~~~
examination.cpp:97:13: warning: unused variable 'col' [-Wunused-variable]
   97 |         int col = 0;
      |             ^~~
examination.cpp:112:13: warning: unused variable 'col' [-Wunused-variable]
  112 |         int col = 0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39388 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 14 ms 39884 KB Output is correct
8 Correct 15 ms 39772 KB Output is correct
9 Correct 14 ms 39772 KB Output is correct
10 Correct 13 ms 39776 KB Output is correct
11 Correct 13 ms 39772 KB Output is correct
12 Correct 11 ms 39752 KB Output is correct
13 Correct 13 ms 39772 KB Output is correct
14 Correct 14 ms 39768 KB Output is correct
15 Correct 13 ms 39768 KB Output is correct
16 Correct 11 ms 39772 KB Output is correct
17 Correct 13 ms 39776 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 53400 KB Output is correct
2 Correct 208 ms 54116 KB Output is correct
3 Correct 203 ms 53440 KB Output is correct
4 Correct 157 ms 52348 KB Output is correct
5 Correct 157 ms 53928 KB Output is correct
6 Correct 99 ms 53448 KB Output is correct
7 Correct 207 ms 54336 KB Output is correct
8 Correct 201 ms 53252 KB Output is correct
9 Correct 195 ms 53444 KB Output is correct
10 Correct 146 ms 52916 KB Output is correct
11 Correct 143 ms 53700 KB Output is correct
12 Correct 75 ms 51404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 53400 KB Output is correct
2 Correct 208 ms 54116 KB Output is correct
3 Correct 203 ms 53440 KB Output is correct
4 Correct 157 ms 52348 KB Output is correct
5 Correct 157 ms 53928 KB Output is correct
6 Correct 99 ms 53448 KB Output is correct
7 Correct 207 ms 54336 KB Output is correct
8 Correct 201 ms 53252 KB Output is correct
9 Correct 195 ms 53444 KB Output is correct
10 Correct 146 ms 52916 KB Output is correct
11 Correct 143 ms 53700 KB Output is correct
12 Correct 75 ms 51404 KB Output is correct
13 Correct 284 ms 54804 KB Output is correct
14 Correct 268 ms 54980 KB Output is correct
15 Correct 205 ms 53188 KB Output is correct
16 Correct 211 ms 54772 KB Output is correct
17 Correct 206 ms 54868 KB Output is correct
18 Correct 129 ms 53192 KB Output is correct
19 Correct 274 ms 55040 KB Output is correct
20 Correct 273 ms 55236 KB Output is correct
21 Correct 276 ms 54980 KB Output is correct
22 Correct 142 ms 53960 KB Output is correct
23 Correct 141 ms 52672 KB Output is correct
24 Correct 78 ms 53192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 39512 KB Output is correct
2 Correct 8 ms 39516 KB Output is correct
3 Correct 8 ms 39516 KB Output is correct
4 Correct 8 ms 39388 KB Output is correct
5 Correct 8 ms 39516 KB Output is correct
6 Correct 8 ms 39516 KB Output is correct
7 Correct 14 ms 39884 KB Output is correct
8 Correct 15 ms 39772 KB Output is correct
9 Correct 14 ms 39772 KB Output is correct
10 Correct 13 ms 39776 KB Output is correct
11 Correct 13 ms 39772 KB Output is correct
12 Correct 11 ms 39752 KB Output is correct
13 Correct 13 ms 39772 KB Output is correct
14 Correct 14 ms 39768 KB Output is correct
15 Correct 13 ms 39768 KB Output is correct
16 Correct 11 ms 39772 KB Output is correct
17 Correct 13 ms 39776 KB Output is correct
18 Correct 10 ms 39772 KB Output is correct
19 Correct 210 ms 53400 KB Output is correct
20 Correct 208 ms 54116 KB Output is correct
21 Correct 203 ms 53440 KB Output is correct
22 Correct 157 ms 52348 KB Output is correct
23 Correct 157 ms 53928 KB Output is correct
24 Correct 99 ms 53448 KB Output is correct
25 Correct 207 ms 54336 KB Output is correct
26 Correct 201 ms 53252 KB Output is correct
27 Correct 195 ms 53444 KB Output is correct
28 Correct 146 ms 52916 KB Output is correct
29 Correct 143 ms 53700 KB Output is correct
30 Correct 75 ms 51404 KB Output is correct
31 Correct 284 ms 54804 KB Output is correct
32 Correct 268 ms 54980 KB Output is correct
33 Correct 205 ms 53188 KB Output is correct
34 Correct 211 ms 54772 KB Output is correct
35 Correct 206 ms 54868 KB Output is correct
36 Correct 129 ms 53192 KB Output is correct
37 Correct 274 ms 55040 KB Output is correct
38 Correct 273 ms 55236 KB Output is correct
39 Correct 276 ms 54980 KB Output is correct
40 Correct 142 ms 53960 KB Output is correct
41 Correct 141 ms 52672 KB Output is correct
42 Correct 78 ms 53192 KB Output is correct
43 Correct 282 ms 56772 KB Output is correct
44 Correct 287 ms 58132 KB Output is correct
45 Correct 282 ms 57700 KB Output is correct
46 Correct 211 ms 55996 KB Output is correct
47 Correct 210 ms 56520 KB Output is correct
48 Correct 122 ms 52432 KB Output is correct
49 Correct 292 ms 57828 KB Output is correct
50 Correct 279 ms 56692 KB Output is correct
51 Correct 284 ms 56972 KB Output is correct
52 Correct 196 ms 54884 KB Output is correct
53 Correct 149 ms 54076 KB Output is correct