Submission #1071533

# Submission time Handle Problem Language Result Execution time Memory
1071533 2024-08-23T08:25:57 Z phong Examination (JOI19_examination) C++17
100 / 100
417 ms 127892 KB
#include<bits/stdc++.h>

#define ll long long
const int nmax = 6e5 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, q;
struct node{
    int x, y, z;
}a[nmax];
vector<pii> tree[nmax << 2];



void build(int id, int l, int r){
    if(l == r){
        tree[id].push_back({a[l].y, a[l].z});
        return;
    }
    int mid = r + l >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    tree[id].resize(r - l + 1);
    merge(tree[id << 1].begin(), tree[id << 1].end(), tree[id << 1 | 1].begin(), tree[id << 1 | 1].end(), tree[id].begin());
}
vector<node> Q[nmax];

void update(int id, int l, int r, int u, int v, int B, int C, int idx){
    if(l > v || r < u) return;
    if(l >= u && r <= v){
        Q[id].push_back({B, C, idx});
        return;
    }
    int mid = r + l>> 1;
    update(id << 1, l, mid, u, v, B, C, idx);
    update(id << 1 | 1, mid + 1, r, u, v, B, C, idx);
}
struct Fen{
    int f[nmax];
    vector<int> tmp;
    void update(int u, int val){
        for(; u ; u -= u &-u) f[u] += val, tmp.push_back(u);
    }
    int get(int u){
        int res = 0;
        for(; u <= 6 * n; u += u&-u) res += f[u];
        return res;
    }
    void clear(){
        for(auto p : tmp){
            f[p] = 0;
        }
        tmp.clear();
    }
}F;
int ans[nmax];
void apply(int id, int l, int r){
    sort(Q[id].begin(), Q[id].end(), [](node a, node b){
        return a.x > b.x;
         });
    int pos = tree[id].size() - 1;
    for(auto [B, C, idx] : Q[id]){
        while(pos >= 0 && tree[id][pos].fi >= B){
            F.update(tree[id][pos].se, 1);
            --pos;
        }
        ans[idx] += F.get(C);
    }
    F.clear();
    if(l != r){
        int mid = r+ l >> 1;
        apply(id << 1, l, mid);
        apply(id << 1 | 1, mid + 1, r);
    }
}
node b[nmax];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> q;
    vector<int> nen;
    for(int i = 1; i <= n; ++i){
        cin >> a[i].x >> a[i].y;
        a[i].z = a[i].x + a[i].y;
        nen.push_back(a[i].x);
        nen.push_back(a[i].y);
        nen.push_back(a[i].z);
    }
    for(int e = 1; e<= q; ++e){
        cin >> b[e].x >> b[e].y>>b[e].z;
        nen.push_back(b[e].x);
        nen.push_back(b[e].y);
        nen.push_back(b[e].z);
    }
    sort(nen.begin(), nen.end());
    nen.erase(unique(nen.begin(), nen.end()), nen.end());
    for(int i = 1; i <= n; ++i){
        a[i].x = lower_bound(nen.begin(), nen.end(), a[i].x) - nen.begin() + 1;
        a[i].y = lower_bound(nen.begin(), nen.end(), a[i].y) - nen.begin() + 1;
        a[i].z = lower_bound(nen.begin(), nen.end(), a[i].z) - nen.begin() + 1;
    }

    sort(a + 1, a + 1 + n, [](node a, node b){
         return a.x < b.x;
         });
    build(1, 1, n);
    for(int e = 1; e <= q; ++e){
        int A, B,C;
        A = lower_bound(nen.begin(), nen.end(), b[e].x) - nen.begin() + 1;
        B = lower_bound(nen.begin(), nen.end(), b[e].y) - nen.begin() + 1;
        C = lower_bound(nen.begin(), nen.end(), b[e].z) - nen.begin() + 1;
        int l = 1 , r = n, kq = n + 1;
        while(l <= r){
            int mid = r + l >> 1;
            if(a[mid].x >= A){
                r = mid - 1;
                kq = mid;
            }
            else l = mid + 1;
        }
//        cout <<kq << ' ';
        update(1, 1, n, kq, n, B, C, e);
    }
    apply(1, 1, n);
    for(int i = 1; i <= q; ++i) cout << ans[i] << endl;

}
/*




*/

Compilation message

examination.cpp: In function 'void build(int, int, int)':
examination.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int mid = r + l >> 1;
      |               ~~^~~
examination.cpp: In function 'void update(int, int, int, int, int, int, int, int)':
examination.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     int mid = r + l>> 1;
      |               ~~^~~
examination.cpp: In function 'void apply(int, int, int)':
examination.cpp:79:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |         int mid = r+ l >> 1;
      |                   ~^~~
examination.cpp: At global scope:
examination.cpp:86:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main(){
      | ^~~~
examination.cpp: In function 'int main()':
examination.cpp:125:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  125 |             int mid = r + l >> 1;
      |                       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 76380 KB Output is correct
2 Correct 13 ms 76380 KB Output is correct
3 Correct 11 ms 74332 KB Output is correct
4 Correct 12 ms 76380 KB Output is correct
5 Correct 12 ms 74284 KB Output is correct
6 Correct 12 ms 76340 KB Output is correct
7 Correct 19 ms 77400 KB Output is correct
8 Correct 20 ms 77400 KB Output is correct
9 Correct 19 ms 77404 KB Output is correct
10 Correct 19 ms 77424 KB Output is correct
11 Correct 25 ms 77396 KB Output is correct
12 Correct 17 ms 77144 KB Output is correct
13 Correct 19 ms 77400 KB Output is correct
14 Correct 17 ms 75352 KB Output is correct
15 Correct 19 ms 75356 KB Output is correct
16 Correct 19 ms 77148 KB Output is correct
17 Correct 18 ms 75356 KB Output is correct
18 Correct 14 ms 74804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 121280 KB Output is correct
2 Correct 332 ms 125540 KB Output is correct
3 Correct 356 ms 126396 KB Output is correct
4 Correct 259 ms 119744 KB Output is correct
5 Correct 214 ms 123836 KB Output is correct
6 Correct 141 ms 118976 KB Output is correct
7 Correct 285 ms 124096 KB Output is correct
8 Correct 321 ms 121276 KB Output is correct
9 Correct 294 ms 123852 KB Output is correct
10 Correct 138 ms 109240 KB Output is correct
11 Correct 244 ms 122048 KB Output is correct
12 Correct 77 ms 101576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 121280 KB Output is correct
2 Correct 332 ms 125540 KB Output is correct
3 Correct 356 ms 126396 KB Output is correct
4 Correct 259 ms 119744 KB Output is correct
5 Correct 214 ms 123836 KB Output is correct
6 Correct 141 ms 118976 KB Output is correct
7 Correct 285 ms 124096 KB Output is correct
8 Correct 321 ms 121276 KB Output is correct
9 Correct 294 ms 123852 KB Output is correct
10 Correct 138 ms 109240 KB Output is correct
11 Correct 244 ms 122048 KB Output is correct
12 Correct 77 ms 101576 KB Output is correct
13 Correct 357 ms 126140 KB Output is correct
14 Correct 353 ms 122260 KB Output is correct
15 Correct 326 ms 121280 KB Output is correct
16 Correct 288 ms 120756 KB Output is correct
17 Correct 237 ms 125892 KB Output is correct
18 Correct 148 ms 118372 KB Output is correct
19 Correct 339 ms 121388 KB Output is correct
20 Correct 349 ms 122816 KB Output is correct
21 Correct 370 ms 123664 KB Output is correct
22 Correct 146 ms 111788 KB Output is correct
23 Correct 254 ms 119916 KB Output is correct
24 Correct 95 ms 101716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 76380 KB Output is correct
2 Correct 13 ms 76380 KB Output is correct
3 Correct 11 ms 74332 KB Output is correct
4 Correct 12 ms 76380 KB Output is correct
5 Correct 12 ms 74284 KB Output is correct
6 Correct 12 ms 76340 KB Output is correct
7 Correct 19 ms 77400 KB Output is correct
8 Correct 20 ms 77400 KB Output is correct
9 Correct 19 ms 77404 KB Output is correct
10 Correct 19 ms 77424 KB Output is correct
11 Correct 25 ms 77396 KB Output is correct
12 Correct 17 ms 77144 KB Output is correct
13 Correct 19 ms 77400 KB Output is correct
14 Correct 17 ms 75352 KB Output is correct
15 Correct 19 ms 75356 KB Output is correct
16 Correct 19 ms 77148 KB Output is correct
17 Correct 18 ms 75356 KB Output is correct
18 Correct 14 ms 74804 KB Output is correct
19 Correct 318 ms 121280 KB Output is correct
20 Correct 332 ms 125540 KB Output is correct
21 Correct 356 ms 126396 KB Output is correct
22 Correct 259 ms 119744 KB Output is correct
23 Correct 214 ms 123836 KB Output is correct
24 Correct 141 ms 118976 KB Output is correct
25 Correct 285 ms 124096 KB Output is correct
26 Correct 321 ms 121276 KB Output is correct
27 Correct 294 ms 123852 KB Output is correct
28 Correct 138 ms 109240 KB Output is correct
29 Correct 244 ms 122048 KB Output is correct
30 Correct 77 ms 101576 KB Output is correct
31 Correct 357 ms 126140 KB Output is correct
32 Correct 353 ms 122260 KB Output is correct
33 Correct 326 ms 121280 KB Output is correct
34 Correct 288 ms 120756 KB Output is correct
35 Correct 237 ms 125892 KB Output is correct
36 Correct 148 ms 118372 KB Output is correct
37 Correct 339 ms 121388 KB Output is correct
38 Correct 349 ms 122816 KB Output is correct
39 Correct 370 ms 123664 KB Output is correct
40 Correct 146 ms 111788 KB Output is correct
41 Correct 254 ms 119916 KB Output is correct
42 Correct 95 ms 101716 KB Output is correct
43 Correct 404 ms 124232 KB Output is correct
44 Correct 397 ms 123592 KB Output is correct
45 Correct 417 ms 127396 KB Output is correct
46 Correct 343 ms 122988 KB Output is correct
47 Correct 267 ms 126648 KB Output is correct
48 Correct 157 ms 116932 KB Output is correct
49 Correct 363 ms 127892 KB Output is correct
50 Correct 388 ms 123064 KB Output is correct
51 Correct 364 ms 124880 KB Output is correct
52 Correct 165 ms 112380 KB Output is correct
53 Correct 253 ms 119952 KB Output is correct