답안 #1106734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106734 2024-10-31T02:13:22 Z luvna Examination (JOI19_examination) C++14
100 / 100
261 ms 21748 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 = 1e6 + 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2552 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 6 ms 708 KB Output is correct
8 Correct 6 ms 764 KB Output is correct
9 Correct 6 ms 592 KB Output is correct
10 Correct 5 ms 2640 KB Output is correct
11 Correct 5 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 5 ms 848 KB Output is correct
14 Correct 5 ms 1016 KB Output is correct
15 Correct 5 ms 700 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 4 ms 2640 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 15608 KB Output is correct
2 Correct 205 ms 15580 KB Output is correct
3 Correct 210 ms 15604 KB Output is correct
4 Correct 151 ms 15612 KB Output is correct
5 Correct 169 ms 15608 KB Output is correct
6 Correct 135 ms 15604 KB Output is correct
7 Correct 210 ms 15604 KB Output is correct
8 Correct 197 ms 15608 KB Output is correct
9 Correct 194 ms 15604 KB Output is correct
10 Correct 152 ms 13816 KB Output is correct
11 Correct 138 ms 15604 KB Output is correct
12 Correct 103 ms 13560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 15608 KB Output is correct
2 Correct 205 ms 15580 KB Output is correct
3 Correct 210 ms 15604 KB Output is correct
4 Correct 151 ms 15612 KB Output is correct
5 Correct 169 ms 15608 KB Output is correct
6 Correct 135 ms 15604 KB Output is correct
7 Correct 210 ms 15604 KB Output is correct
8 Correct 197 ms 15608 KB Output is correct
9 Correct 194 ms 15604 KB Output is correct
10 Correct 152 ms 13816 KB Output is correct
11 Correct 138 ms 15604 KB Output is correct
12 Correct 103 ms 13560 KB Output is correct
13 Correct 239 ms 14072 KB Output is correct
14 Correct 238 ms 14836 KB Output is correct
15 Correct 209 ms 15572 KB Output is correct
16 Correct 181 ms 13396 KB Output is correct
17 Correct 217 ms 13556 KB Output is correct
18 Correct 139 ms 14580 KB Output is correct
19 Correct 235 ms 14076 KB Output is correct
20 Correct 236 ms 14580 KB Output is correct
21 Correct 241 ms 14068 KB Output is correct
22 Correct 149 ms 13812 KB Output is correct
23 Correct 138 ms 15536 KB Output is correct
24 Correct 102 ms 13568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2552 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 6 ms 708 KB Output is correct
8 Correct 6 ms 764 KB Output is correct
9 Correct 6 ms 592 KB Output is correct
10 Correct 5 ms 2640 KB Output is correct
11 Correct 5 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 5 ms 848 KB Output is correct
14 Correct 5 ms 1016 KB Output is correct
15 Correct 5 ms 700 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 4 ms 2640 KB Output is correct
18 Correct 3 ms 592 KB Output is correct
19 Correct 201 ms 15608 KB Output is correct
20 Correct 205 ms 15580 KB Output is correct
21 Correct 210 ms 15604 KB Output is correct
22 Correct 151 ms 15612 KB Output is correct
23 Correct 169 ms 15608 KB Output is correct
24 Correct 135 ms 15604 KB Output is correct
25 Correct 210 ms 15604 KB Output is correct
26 Correct 197 ms 15608 KB Output is correct
27 Correct 194 ms 15604 KB Output is correct
28 Correct 152 ms 13816 KB Output is correct
29 Correct 138 ms 15604 KB Output is correct
30 Correct 103 ms 13560 KB Output is correct
31 Correct 239 ms 14072 KB Output is correct
32 Correct 238 ms 14836 KB Output is correct
33 Correct 209 ms 15572 KB Output is correct
34 Correct 181 ms 13396 KB Output is correct
35 Correct 217 ms 13556 KB Output is correct
36 Correct 139 ms 14580 KB Output is correct
37 Correct 235 ms 14076 KB Output is correct
38 Correct 236 ms 14580 KB Output is correct
39 Correct 241 ms 14068 KB Output is correct
40 Correct 149 ms 13812 KB Output is correct
41 Correct 138 ms 15536 KB Output is correct
42 Correct 102 ms 13568 KB Output is correct
43 Correct 247 ms 14580 KB Output is correct
44 Correct 252 ms 20980 KB Output is correct
45 Correct 254 ms 21748 KB Output is correct
46 Correct 171 ms 16756 KB Output is correct
47 Correct 214 ms 17140 KB Output is correct
48 Correct 118 ms 14336 KB Output is correct
49 Correct 241 ms 21492 KB Output is correct
50 Correct 261 ms 19160 KB Output is correct
51 Correct 243 ms 21492 KB Output is correct
52 Correct 191 ms 15352 KB Output is correct
53 Correct 138 ms 17912 KB Output is correct