답안 #684904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684904 2023-01-22T19:26:29 Z izanbf Examination (JOI19_examination) C++14
100 / 100
409 ms 26340 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define endl "\n"
//~ #define int long long
 
typedef long long int ll;
 
const int MOD = 1e9 + 7;
const int maxN = 200000;
 
bool cmp(pair<int, int> a, pair<int, int> b){
    return a.first + a.second > b.first + b.second;
}
 
bool cmp2(tuple<int, int, int, int> a, tuple<int, int, int, int> b){
    return get<2>(a) > get<2>(b);
}
 


struct segTree {
    vector<ll> bit;

    void init(int n) {
        bit.assign(n+1, 0);
    }
 
    ll sum(int r) {
        ll sum = 0;
        for (; r > 0; r -= r&-r)
            sum += bit[r];
        return sum;
    }
     
    ll sum(int l, int r) {
        return sum(r) - sum(l-1);
    }
     
    void add(int r, ll delta) {
        for (; r < bit.size(); r += r&-r)
            bit[r] += delta;
    }

    void set(int r, ll x) {
        add(r+1, x);
    }
};

 
 
void solve(){
    int n, q; cin >> n >> q;
    vector<pair<int, int>> v(n);
    set<int> sa;
    set<int> sb;
    for(int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        v[i] = {x, y};
        sa.insert(x);
        sb.insert(y);
    }
    map<int, int> a;
    map<int, int> b;
    int curr = 1;
    for(auto x : sa){
        a[x] = curr;
        curr++;
    }
    segTree sta; sta.init(curr);
    int sza = curr;
    curr = 1;
    for(auto x : sb){
        b[x] = curr;
        curr++;
    }
    segTree stb; stb.init(curr);
    int szb = curr;
    sort(v.begin(), v.end(), cmp);
    vector<tuple<int, int, int, int>> queries(q);
    for(int i = 0; i < q; i++){
        int x, y, z; cin >> x >> y >> z;
        int nx = sza;
        auto it = a.lower_bound(x);
        if(it != a.end()) nx = (*it).second;
        int ny = szb;
        it = b.lower_bound(y);
        if(it != b.end()) ny = (*it).second;
        queries[i] = {nx, ny, max(z, x + y), i};
    }
    sort(queries.begin(), queries.end(), cmp2);
    vector<int> ans(q);
    curr = 0;
    for(int i = 0; i < q; i++){
        while(curr < n && v[curr].first + v[curr].second >= get<2>(queries[i])){
            sta.set(a[v[curr].first], 1);
            stb.set(b[v[curr].second], 1);
            curr++;
        }
        int total = curr - sta.sum(1, get<0>(queries[i])) - stb.sum(1, get<1>(queries[i]));
        ans[get<3>(queries[i])] = total;
    }
    for(int x : ans) cout << x << endl;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("inpt.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    //~ int tt; cin >> tt;
    int tt = 1;
    for(int t = 1; t <= tt; t++){
        solve();
    }
}

Compilation message

examination.cpp: In member function 'void segTree::add(int, ll)':
examination.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (; r < bit.size(); r += r&-r)
      |                ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 1136 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 6 ms 1108 KB Output is correct
14 Correct 6 ms 1156 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 4 ms 708 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 276 ms 18836 KB Output is correct
2 Correct 268 ms 18732 KB Output is correct
3 Correct 331 ms 18764 KB Output is correct
4 Correct 135 ms 11764 KB Output is correct
5 Correct 161 ms 11824 KB Output is correct
6 Correct 59 ms 4564 KB Output is correct
7 Correct 237 ms 18740 KB Output is correct
8 Correct 240 ms 18756 KB Output is correct
9 Correct 239 ms 18736 KB Output is correct
10 Correct 126 ms 11512 KB Output is correct
11 Correct 137 ms 11520 KB Output is correct
12 Correct 47 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 276 ms 18836 KB Output is correct
2 Correct 268 ms 18732 KB Output is correct
3 Correct 331 ms 18764 KB Output is correct
4 Correct 135 ms 11764 KB Output is correct
5 Correct 161 ms 11824 KB Output is correct
6 Correct 59 ms 4564 KB Output is correct
7 Correct 237 ms 18740 KB Output is correct
8 Correct 240 ms 18756 KB Output is correct
9 Correct 239 ms 18736 KB Output is correct
10 Correct 126 ms 11512 KB Output is correct
11 Correct 137 ms 11520 KB Output is correct
12 Correct 47 ms 4176 KB Output is correct
13 Correct 262 ms 18736 KB Output is correct
14 Correct 281 ms 18676 KB Output is correct
15 Correct 263 ms 18760 KB Output is correct
16 Correct 149 ms 12136 KB Output is correct
17 Correct 141 ms 12156 KB Output is correct
18 Correct 61 ms 4660 KB Output is correct
19 Correct 275 ms 18664 KB Output is correct
20 Correct 277 ms 18756 KB Output is correct
21 Correct 257 ms 18736 KB Output is correct
22 Correct 141 ms 11624 KB Output is correct
23 Correct 137 ms 11596 KB Output is correct
24 Correct 57 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 6 ms 1136 KB Output is correct
8 Correct 6 ms 1100 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 6 ms 1108 KB Output is correct
14 Correct 6 ms 1156 KB Output is correct
15 Correct 6 ms 1108 KB Output is correct
16 Correct 4 ms 708 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 276 ms 18836 KB Output is correct
20 Correct 268 ms 18732 KB Output is correct
21 Correct 331 ms 18764 KB Output is correct
22 Correct 135 ms 11764 KB Output is correct
23 Correct 161 ms 11824 KB Output is correct
24 Correct 59 ms 4564 KB Output is correct
25 Correct 237 ms 18740 KB Output is correct
26 Correct 240 ms 18756 KB Output is correct
27 Correct 239 ms 18736 KB Output is correct
28 Correct 126 ms 11512 KB Output is correct
29 Correct 137 ms 11520 KB Output is correct
30 Correct 47 ms 4176 KB Output is correct
31 Correct 262 ms 18736 KB Output is correct
32 Correct 281 ms 18676 KB Output is correct
33 Correct 263 ms 18760 KB Output is correct
34 Correct 149 ms 12136 KB Output is correct
35 Correct 141 ms 12156 KB Output is correct
36 Correct 61 ms 4660 KB Output is correct
37 Correct 275 ms 18664 KB Output is correct
38 Correct 277 ms 18756 KB Output is correct
39 Correct 257 ms 18736 KB Output is correct
40 Correct 141 ms 11624 KB Output is correct
41 Correct 137 ms 11596 KB Output is correct
42 Correct 57 ms 4184 KB Output is correct
43 Correct 390 ms 26232 KB Output is correct
44 Correct 409 ms 26340 KB Output is correct
45 Correct 337 ms 26228 KB Output is correct
46 Correct 172 ms 16056 KB Output is correct
47 Correct 174 ms 16088 KB Output is correct
48 Correct 59 ms 4388 KB Output is correct
49 Correct 315 ms 26204 KB Output is correct
50 Correct 365 ms 26228 KB Output is correct
51 Correct 321 ms 26224 KB Output is correct
52 Correct 180 ms 15880 KB Output is correct
53 Correct 197 ms 15924 KB Output is correct