Submission #1106733

# Submission time Handle Problem Language Result Execution time Memory
1106733 2024-10-31T02:12:39 Z luvna Examination (JOI19_examination) C++17
43 / 100
243 ms 20736 KB
#include<bits/stdc++.h>

#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()

using namespace std;

template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand_range(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}

const int N = 1e5 + 15;

struct node{
    int x, y, z, id;
};

bool cmp(node a, node b){
    return (a.z == b.z) ? a.id < b.id : a.z > b.z;
}

bool cmp1(node a, node b){
    return a.x > b.x;
}

int n, q;
vector<node> evt;
vector<int> compress;
int bit[N];

void update(int idx, int val){
    for(;idx <= sz(compress); idx += (idx & (-idx))) bit[idx] += val;
}

int get(int idx){ int res = 0;
    for(;idx; idx -= (idx & (-idx))) res +=  bit[idx];
    return res;
}

int ans[N];
deque<int> save;

void cdq(int l, int r){
    if(l >= r) return;

    int mid = (l+r) >> 1;

    vector<node> upd, ask;
    for(int i = l; i <= mid; i++) if(evt[i].id == -1) upd.pub(evt[i]);
    for(int i = mid+1; i <= r; i++) if(evt[i].id != -1) ask.pub(evt[i]);

    sort(all(upd),cmp1); sort(all(ask),cmp1);

    for(int i = 0, j = 0; i < sz(ask); i++){
        while(j < sz(upd) && upd[j].x >= ask[i].x){
            update(upd[j].y, 1);
            save.push_back(upd[j].y);
            j++;
        }
        ans[ask[i].id] += get(sz(compress)) - get(ask[i].y-1);
    }

    while(!save.empty()) update(save.back(), -1), save.pop_back();

    cdq(l,mid);
    cdq(mid+1,r);
}

void solve(){
    cin >> n >> q;

    for(int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        evt.pub({x,y,x+y,-1});
        compress.pub(y);
    }

    for(int i = 1; i <= q; i++){
        int x, y, z; cin >> x >> y >> z;
        evt.pub({x,y,z,i});
        compress.pub(y);
    }

    sort(all(compress)); compact(compress);
    for(int i = 0; i < sz(evt); i++) evt[i].y = lower_bound(all(compress), evt[i].y) - compress.begin() + 1;
    sort(all(evt),cmp);

    //for(auto [x, y, z, id] : evt) cout << id << "   " << x << " " << y << " " << z << endl;

    cdq(0,sz(evt)-1);

    for(int i = 1; i <= q; i++) cout << ans[i] << endl;
}

signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);

    #define task "task"

    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    int t; t = 1; //cin >> t;
    while(t--) solve();
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 6 ms 880 KB Output is correct
8 Correct 6 ms 848 KB Output is correct
9 Correct 7 ms 848 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 7 ms 636 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 5 ms 848 KB Output is correct
14 Correct 6 ms 848 KB Output is correct
15 Correct 5 ms 848 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 5 ms 848 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 14324 KB Output is correct
2 Correct 203 ms 14436 KB Output is correct
3 Correct 204 ms 14528 KB Output is correct
4 Correct 158 ms 13300 KB Output is correct
5 Correct 169 ms 13780 KB Output is correct
6 Correct 124 ms 12536 KB Output is correct
7 Correct 205 ms 14324 KB Output is correct
8 Correct 196 ms 14324 KB Output is correct
9 Correct 194 ms 14068 KB Output is correct
10 Correct 144 ms 13556 KB Output is correct
11 Correct 134 ms 13256 KB Output is correct
12 Correct 97 ms 12536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 14324 KB Output is correct
2 Correct 203 ms 14436 KB Output is correct
3 Correct 204 ms 14528 KB Output is correct
4 Correct 158 ms 13300 KB Output is correct
5 Correct 169 ms 13780 KB Output is correct
6 Correct 124 ms 12536 KB Output is correct
7 Correct 205 ms 14324 KB Output is correct
8 Correct 196 ms 14324 KB Output is correct
9 Correct 194 ms 14068 KB Output is correct
10 Correct 144 ms 13556 KB Output is correct
11 Correct 134 ms 13256 KB Output is correct
12 Correct 97 ms 12536 KB Output is correct
13 Correct 237 ms 13300 KB Output is correct
14 Correct 233 ms 15984 KB Output is correct
15 Correct 206 ms 14324 KB Output is correct
16 Correct 172 ms 11768 KB Output is correct
17 Correct 205 ms 12028 KB Output is correct
18 Correct 129 ms 11676 KB Output is correct
19 Correct 243 ms 13424 KB Output is correct
20 Correct 243 ms 13920 KB Output is correct
21 Correct 230 ms 13292 KB Output is correct
22 Correct 144 ms 13560 KB Output is correct
23 Correct 132 ms 13304 KB Output is correct
24 Correct 102 ms 12668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 6 ms 880 KB Output is correct
8 Correct 6 ms 848 KB Output is correct
9 Correct 7 ms 848 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 7 ms 636 KB Output is correct
12 Correct 4 ms 592 KB Output is correct
13 Correct 5 ms 848 KB Output is correct
14 Correct 6 ms 848 KB Output is correct
15 Correct 5 ms 848 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 5 ms 848 KB Output is correct
18 Correct 4 ms 592 KB Output is correct
19 Correct 211 ms 14324 KB Output is correct
20 Correct 203 ms 14436 KB Output is correct
21 Correct 204 ms 14528 KB Output is correct
22 Correct 158 ms 13300 KB Output is correct
23 Correct 169 ms 13780 KB Output is correct
24 Correct 124 ms 12536 KB Output is correct
25 Correct 205 ms 14324 KB Output is correct
26 Correct 196 ms 14324 KB Output is correct
27 Correct 194 ms 14068 KB Output is correct
28 Correct 144 ms 13556 KB Output is correct
29 Correct 134 ms 13256 KB Output is correct
30 Correct 97 ms 12536 KB Output is correct
31 Correct 237 ms 13300 KB Output is correct
32 Correct 233 ms 15984 KB Output is correct
33 Correct 206 ms 14324 KB Output is correct
34 Correct 172 ms 11768 KB Output is correct
35 Correct 205 ms 12028 KB Output is correct
36 Correct 129 ms 11676 KB Output is correct
37 Correct 243 ms 13424 KB Output is correct
38 Correct 243 ms 13920 KB Output is correct
39 Correct 230 ms 13292 KB Output is correct
40 Correct 144 ms 13560 KB Output is correct
41 Correct 132 ms 13304 KB Output is correct
42 Correct 102 ms 12668 KB Output is correct
43 Runtime error 109 ms 20736 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -