Submission #839475

# Submission time Handle Problem Language Result Execution time Memory
839475 2023-08-30T06:15:01 Z vjudge1 Examination (JOI19_examination) C++14
100 / 100
1252 ms 8140 KB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define setpre(i) setprecision(i)<<fixed
#define foru(i, a, b) for(int i=a;i<=b;++i)
#define ford(i, a, b) for(int i=a;i>=b;--i)
#define mp make_pair
#define moo cout<<"moo "
#define fi first
#define se second

ll lmod = 1e9 + 7;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

struct query{
    int a, b, c, idx;
    query(int a, int b, int c, int idx): a(a), b(b), c(c), idx(idx){}
    const bool operator < (const query &q) const { return b > q.b; }
};

struct Fenwick{
    int n; vi bit;
    Fenwick(int n): n(n){
        bit.resize(n + 1);
    }
    void update(int idx, int diff){
        while(idx <= n){
            bit[idx] += diff;
            idx += idx & -idx;
        }
    }
    int sum(int idx){
        int ans = 0;
        while(idx >= 1){    
            ans += bit[idx];
            idx -= idx & -idx;
        }
        return ans;
    }
};

int s[100001], t[100001], sumpos[100001];
ii arrs[100001], arrt[100001];
int arrsum[100001];
vector<query> queries[1001];
int cnt[100001];
int ans[100001];

int main(){
	// freopen("input.inp", "r", stdin);
	// freopen("output.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    foru(i, 1, n){
        cin >> s[i] >> t[i];
        arrs[i] = mp(s[i], i);
        arrt[i] = mp(t[i], i);
        arrsum[i] = s[i] + t[i];
    }
    int sz = sqrt(n);
    sort(arrsum + 1, arrsum + n + 1);
    sort(arrs + 1, arrs + n + 1);
    sort(arrt + 1, arrt + n + 1);
    foru(i, 1, n){
        int z = lower_bound(arrsum + 1, arrsum + n + 1, s[i] + t[i]) - arrsum;
        sumpos[i] = z;
    }
    int maxblock = 0;
    foru(i, 1, q){
        int x, y, z; cin >> x >> y >> z;
        int a = lower_bound(arrs + 1, arrs + n + 1, mp(x, 0)) - arrs;
        int b = lower_bound(arrt + 1, arrt + n + 1, mp(y, 0)) - arrt;
        int c = lower_bound(arrsum + 1, arrsum + n + 1, z) - arrsum;
        queries[a / sz].pb(query(a, b, c, i));
        maxblock = max(maxblock, a / sz);
    }
    Fenwick f(n);
    memset(cnt, 0, sizeof cnt);
    int ptrl = n + 1, ptrr = n + 1;
    ford(i, maxblock, 0){
        sort(queries[i].begin(), queries[i].end());
        for(query que: queries[i]){
            
            int a = que.a, b = que.b, c = que.c, idx = que.idx;
            // moo << a << " " << b << " " << c << " " << idx << endl;
            while(ptrl > a){
                ptrl--;
                cnt[arrs[ptrl].se]++;
                if(cnt[arrs[ptrl].se] == 2){
                    f.update(sumpos[arrs[ptrl].se], 1);  
                    // cout << sumpos[arrs[ptrl].se] << " " << 1 << endl;
                } 
            }
            while(ptrl < a){
                cnt[arrs[ptrl].se]--;
                if(cnt[arrs[ptrl].se] == 1) {
                    f.update(sumpos[arrs[ptrl].se], -1);   
                    // cout << sumpos[arrs[ptrl].se] << " " << -1 << endl;
                }
                ptrl++;             
            }
            while(ptrr > b){
                ptrr--;
                cnt[arrt[ptrr].se]++;
                if(cnt[arrt[ptrr].se] == 2) {
                    f.update(sumpos[arrt[ptrr].se], 1);
                    // cout << sumpos[arrt[ptrr].se] << " " << 1 << endl;
                }
            }
            while(ptrr < b){
                cnt[arrt[ptrr].se]--;
                if(cnt[arrt[ptrr].se] == 1) {
                    f.update(sumpos[arrt[ptrr].se], -1);   
                    // cout << sumpos[arrt[ptrr].se] << " " << -1 << endl;
                }
                ptrr++;             
            }
            ans[idx] = f.sum(n) - f.sum(c - 1);
        }
    }
    foru(i, 1, q) cout << ans[i] << '\n';
    // foru(i, 1, n) cout << f.sum(i) - f.sum(i - 1) << " ";
    // cout << endl;
//	fclose(stdout);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 724 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 724 KB Output is correct
5 Correct 0 ms 724 KB Output is correct
6 Correct 0 ms 724 KB Output is correct
7 Correct 7 ms 988 KB Output is correct
8 Correct 7 ms 980 KB Output is correct
9 Correct 7 ms 980 KB Output is correct
10 Correct 6 ms 980 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 7 ms 996 KB Output is correct
14 Correct 7 ms 940 KB Output is correct
15 Correct 7 ms 980 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 6 ms 988 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1213 ms 8040 KB Output is correct
2 Correct 1198 ms 8004 KB Output is correct
3 Correct 1193 ms 7992 KB Output is correct
4 Correct 896 ms 7988 KB Output is correct
5 Correct 127 ms 7152 KB Output is correct
6 Correct 90 ms 7132 KB Output is correct
7 Correct 328 ms 7220 KB Output is correct
8 Correct 337 ms 7992 KB Output is correct
9 Correct 239 ms 7300 KB Output is correct
10 Correct 91 ms 6520 KB Output is correct
11 Correct 907 ms 7832 KB Output is correct
12 Correct 45 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1213 ms 8040 KB Output is correct
2 Correct 1198 ms 8004 KB Output is correct
3 Correct 1193 ms 7992 KB Output is correct
4 Correct 896 ms 7988 KB Output is correct
5 Correct 127 ms 7152 KB Output is correct
6 Correct 90 ms 7132 KB Output is correct
7 Correct 328 ms 7220 KB Output is correct
8 Correct 337 ms 7992 KB Output is correct
9 Correct 239 ms 7300 KB Output is correct
10 Correct 91 ms 6520 KB Output is correct
11 Correct 907 ms 7832 KB Output is correct
12 Correct 45 ms 6488 KB Output is correct
13 Correct 1220 ms 8000 KB Output is correct
14 Correct 1232 ms 8016 KB Output is correct
15 Correct 1215 ms 7996 KB Output is correct
16 Correct 895 ms 8020 KB Output is correct
17 Correct 151 ms 7152 KB Output is correct
18 Correct 93 ms 7416 KB Output is correct
19 Correct 1252 ms 8008 KB Output is correct
20 Correct 1243 ms 8140 KB Output is correct
21 Correct 600 ms 8016 KB Output is correct
22 Correct 94 ms 6556 KB Output is correct
23 Correct 903 ms 7908 KB Output is correct
24 Correct 44 ms 6548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 724 KB Output is correct
3 Correct 0 ms 724 KB Output is correct
4 Correct 0 ms 724 KB Output is correct
5 Correct 0 ms 724 KB Output is correct
6 Correct 0 ms 724 KB Output is correct
7 Correct 7 ms 988 KB Output is correct
8 Correct 7 ms 980 KB Output is correct
9 Correct 7 ms 980 KB Output is correct
10 Correct 6 ms 980 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 3 ms 980 KB Output is correct
13 Correct 7 ms 996 KB Output is correct
14 Correct 7 ms 940 KB Output is correct
15 Correct 7 ms 980 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 6 ms 988 KB Output is correct
18 Correct 2 ms 980 KB Output is correct
19 Correct 1213 ms 8040 KB Output is correct
20 Correct 1198 ms 8004 KB Output is correct
21 Correct 1193 ms 7992 KB Output is correct
22 Correct 896 ms 7988 KB Output is correct
23 Correct 127 ms 7152 KB Output is correct
24 Correct 90 ms 7132 KB Output is correct
25 Correct 328 ms 7220 KB Output is correct
26 Correct 337 ms 7992 KB Output is correct
27 Correct 239 ms 7300 KB Output is correct
28 Correct 91 ms 6520 KB Output is correct
29 Correct 907 ms 7832 KB Output is correct
30 Correct 45 ms 6488 KB Output is correct
31 Correct 1220 ms 8000 KB Output is correct
32 Correct 1232 ms 8016 KB Output is correct
33 Correct 1215 ms 7996 KB Output is correct
34 Correct 895 ms 8020 KB Output is correct
35 Correct 151 ms 7152 KB Output is correct
36 Correct 93 ms 7416 KB Output is correct
37 Correct 1252 ms 8008 KB Output is correct
38 Correct 1243 ms 8140 KB Output is correct
39 Correct 600 ms 8016 KB Output is correct
40 Correct 94 ms 6556 KB Output is correct
41 Correct 903 ms 7908 KB Output is correct
42 Correct 44 ms 6548 KB Output is correct
43 Correct 1216 ms 8016 KB Output is correct
44 Correct 1217 ms 8028 KB Output is correct
45 Correct 1204 ms 7976 KB Output is correct
46 Correct 906 ms 8048 KB Output is correct
47 Correct 141 ms 6924 KB Output is correct
48 Correct 98 ms 7140 KB Output is correct
49 Correct 341 ms 7224 KB Output is correct
50 Correct 351 ms 8008 KB Output is correct
51 Correct 256 ms 7236 KB Output is correct
52 Correct 108 ms 6520 KB Output is correct
53 Correct 892 ms 7892 KB Output is correct