답안 #1099704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099704 2024-10-12T04:06:32 Z Zero_OP Examination (JOI19_examination) C++14
100 / 100
385 ms 12024 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"

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

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

using ll = long long;
using ld = long double;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); }
template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); }

const int MAX = 2e5 + 5;

int n, q, math[MAX], informatics[MAX], ans[MAX];

struct event{
    int x, y, z, id;
    bool operator < (const event& o) const{
        return make_tuple(-x, -y, -z, id) < make_tuple(-o.x, -o.y, -o.z, o.id);
    }
};

struct Fenwick{
    vector<int> bit;
    Fenwick(int n) : bit(n + 1, 0) {}

    void update(int id, int val){
        for(; id > 0; id -= id & (-id)){
            bit[id] += val;
        }
    }

    int query(int id){
        int sum = 0;
        for(; id < sz(bit); id += id & (-id)){
            sum += bit[id];
        }
        return sum;
    }
};

void cdq(int l, int r, vector<event>& events, Fenwick& fenwick){
    if(l >= r) return;
    int mid = l + r >> 1;

    cdq(l, mid, events, fenwick);
    cdq(mid + 1, r, events, fenwick);

    vector<int> id(r - l + 1);
    iota(all(id), l);

    sort(all(id), [&](int i, int j){
        return make_tuple(-events[i].y, -events[i].z, events[i].id) < make_tuple(-events[j].y, -events[j].z, events[j].id);
    });

    stack<int> st;
    rep(t, 0, sz(id)){
        int i = id[t];

        if(events[i].id == -1 && i <= mid){
            fenwick.update(events[i].z, +1);
            st.push(events[i].z);
        }

        if(events[i].id > 0 && i > mid){
            ans[events[i].id] += fenwick.query(events[i].z);
        }
    }

    while(!st.empty()){
        fenwick.update(st.top(), -1); st.pop();
    }
}

void testcase(){
    cin >> n >> q;
    vector<event> events;
    vector<int> Oz;
    FOR(i, 1, n){
        int x, y;
        cin >> x >> y;
        events.push_back({x, y, x + y, -1});
        Oz.push_back(x + y);
    }

    FOR(i, 1, q){
        int x, y, z;
        cin >> x >> y >> z;
        events.push_back({x, y, z, i});
        Oz.push_back(z);
    }

    sort(all(Oz));
    compact(Oz);

    rep(i, 0, sz(events)){
        events[i].z = lower_bound(all(Oz), events[i].z) - Oz.begin() + 1;
    }

    sort(all(events));

    Fenwick fenwick(sz(Oz));
    cdq(0, sz(events) - 1, events, fenwick);

    FOR(i, 1, q){
        cout << ans[i] << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    #define filename "task"
    if(fopen(filename".inp", "r")){
        freopen(filename".inp", "r", stdin);
        freopen(filename".out", "w", stdout);
    }

    int T = 1; //cin >> T;
    while(T--) testcase();

    return 0;
}

Compilation message

examination.cpp: In function 'bool minimize(T&, const T&)':
examination.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |     if(a > b) return a = b, true; return false;
      |     ^~
examination.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
examination.cpp: In function 'bool maximize(T&, const T&)':
examination.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |     if(a < b) return a = b, true; return false;
      |     ^~
examination.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
examination.cpp: In function 'void cdq(int, int, std::vector<event>&, Fenwick&)':
examination.cpp:62:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |     int mid = l + r >> 1;
      |               ~~^~~
examination.cpp: In function 'int main()':
examination.cpp:134:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |         freopen(filename".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         freopen(filename".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 7 ms 856 KB Output is correct
8 Correct 7 ms 736 KB Output is correct
9 Correct 7 ms 828 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 5 ms 764 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 732 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 6 ms 600 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 7 ms 616 KB Output is correct
18 Correct 5 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 9460 KB Output is correct
2 Correct 320 ms 9468 KB Output is correct
3 Correct 314 ms 9528 KB Output is correct
4 Correct 357 ms 8712 KB Output is correct
5 Correct 195 ms 8736 KB Output is correct
6 Correct 131 ms 8132 KB Output is correct
7 Correct 304 ms 9460 KB Output is correct
8 Correct 310 ms 9352 KB Output is correct
9 Correct 311 ms 9396 KB Output is correct
10 Correct 200 ms 8612 KB Output is correct
11 Correct 305 ms 8696 KB Output is correct
12 Correct 127 ms 7668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 9460 KB Output is correct
2 Correct 320 ms 9468 KB Output is correct
3 Correct 314 ms 9528 KB Output is correct
4 Correct 357 ms 8712 KB Output is correct
5 Correct 195 ms 8736 KB Output is correct
6 Correct 131 ms 8132 KB Output is correct
7 Correct 304 ms 9460 KB Output is correct
8 Correct 310 ms 9352 KB Output is correct
9 Correct 311 ms 9396 KB Output is correct
10 Correct 200 ms 8612 KB Output is correct
11 Correct 305 ms 8696 KB Output is correct
12 Correct 127 ms 7668 KB Output is correct
13 Correct 345 ms 9976 KB Output is correct
14 Correct 344 ms 9980 KB Output is correct
15 Correct 313 ms 9464 KB Output is correct
16 Correct 361 ms 9100 KB Output is correct
17 Correct 212 ms 9208 KB Output is correct
18 Correct 138 ms 8184 KB Output is correct
19 Correct 335 ms 9888 KB Output is correct
20 Correct 353 ms 9980 KB Output is correct
21 Correct 335 ms 9976 KB Output is correct
22 Correct 197 ms 8692 KB Output is correct
23 Correct 306 ms 8700 KB Output is correct
24 Correct 128 ms 7684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 7 ms 856 KB Output is correct
8 Correct 7 ms 736 KB Output is correct
9 Correct 7 ms 828 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 5 ms 764 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 6 ms 732 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 6 ms 600 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 7 ms 616 KB Output is correct
18 Correct 5 ms 752 KB Output is correct
19 Correct 335 ms 9460 KB Output is correct
20 Correct 320 ms 9468 KB Output is correct
21 Correct 314 ms 9528 KB Output is correct
22 Correct 357 ms 8712 KB Output is correct
23 Correct 195 ms 8736 KB Output is correct
24 Correct 131 ms 8132 KB Output is correct
25 Correct 304 ms 9460 KB Output is correct
26 Correct 310 ms 9352 KB Output is correct
27 Correct 311 ms 9396 KB Output is correct
28 Correct 200 ms 8612 KB Output is correct
29 Correct 305 ms 8696 KB Output is correct
30 Correct 127 ms 7668 KB Output is correct
31 Correct 345 ms 9976 KB Output is correct
32 Correct 344 ms 9980 KB Output is correct
33 Correct 313 ms 9464 KB Output is correct
34 Correct 361 ms 9100 KB Output is correct
35 Correct 212 ms 9208 KB Output is correct
36 Correct 138 ms 8184 KB Output is correct
37 Correct 335 ms 9888 KB Output is correct
38 Correct 353 ms 9980 KB Output is correct
39 Correct 335 ms 9976 KB Output is correct
40 Correct 197 ms 8692 KB Output is correct
41 Correct 306 ms 8700 KB Output is correct
42 Correct 128 ms 7684 KB Output is correct
43 Correct 352 ms 11960 KB Output is correct
44 Correct 358 ms 11840 KB Output is correct
45 Correct 367 ms 11788 KB Output is correct
46 Correct 385 ms 10232 KB Output is correct
47 Correct 226 ms 10260 KB Output is correct
48 Correct 149 ms 7956 KB Output is correct
49 Correct 346 ms 12024 KB Output is correct
50 Correct 338 ms 11900 KB Output is correct
51 Correct 334 ms 11772 KB Output is correct
52 Correct 212 ms 10240 KB Output is correct
53 Correct 299 ms 9372 KB Output is correct