답안 #768742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768742 2023-06-28T14:15:09 Z raysh07 Examination (JOI19_examination) C++17
100 / 100
658 ms 62096 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

struct query{
    int x, y, s, i;
};

struct score{
    int x, y, s;
};

const int N = 1e5 + 69;
int ans[N], n, q;
query Q[N];
score A[N];
int f[4 * N][2];
int mx;

bool c1(score a, score b){
    return a.s > b.s;
}

bool c2(query a, query b){
    return a.s > b.s;
}

void upd(int x, int j){
    for (int i = x; i <= mx; i += i & (-i)){
        f[i][j]++;
    }
}

int query(int x, int j){
    int res = 0;
    for (int i = x; i; i -= i & (-i)){
        res += f[i][j];
    }
    return res;
}

void Solve() 
{
    cin >> n >> q;
    
    set <int> st;
    
    for (int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        
        A[i].x = x;
        A[i].y = y;
        A[i].s = x + y;
        
        st.insert(A[i].x);
        st.insert(A[i].y);
    }
    
    for (int i = 1; i <= q; i++){
        cin >> Q[i].x >> Q[i].y >> Q[i].s;
        
        Q[i].s = max(Q[i].s, Q[i].x + Q[i].y);
        Q[i].i = i;
        st.insert(Q[i].x);
        st.insert(Q[i].y);
    }
    
    sort(A + 1, A + n + 1, c1);
    sort(Q + 1, Q + q + 1, c2);
    
    map <int, int> mp;
    int pr = 0;
    for (auto x : st){
        mp[x] = ++pr;
    }
    mx = pr;
    
    for (int i = 1; i <= n; i++){
        A[i].x = mp[A[i].x];
        A[i].y = mp[A[i].y];
    }
    
    for (int i = 1; i <= q; i++){
        Q[i].x = mp[Q[i].x];
        Q[i].y = mp[Q[i].y];
    }
    
    int ptr = 1;
    
    // for (int i = 1; i <= n; i++){
    //     cout << A[i].s << " ";
    // }
    // cout << "\n";
    for (int i = 1; i <= q; i++){
        while (ptr <= n && A[ptr].s >= Q[i].s){
           // cout << "ADDED " << A[ptr].x << " " << A[ptr].y << "\n";
            upd(A[ptr].x, 0);
            upd(A[ptr].y, 1);
            ptr++;
        }
        
      //  cout << Q[i].i << " " << ptr << " " << Q[i].x << " " << Q[i].y << " ";
        int x = query(Q[i].x - 1, 0); 
        x += query(Q[i].y - 1, 1);
        ans[Q[i].i] = ptr - 1 - x;
    }
    
    for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 8 ms 2176 KB Output is correct
8 Correct 8 ms 2112 KB Output is correct
9 Correct 7 ms 2112 KB Output is correct
10 Correct 5 ms 1368 KB Output is correct
11 Correct 5 ms 1388 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 7 ms 2180 KB Output is correct
14 Correct 7 ms 2132 KB Output is correct
15 Correct 7 ms 2132 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 4 ms 1364 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 21876 KB Output is correct
2 Correct 231 ms 21932 KB Output is correct
3 Correct 217 ms 21856 KB Output is correct
4 Correct 154 ms 19744 KB Output is correct
5 Correct 163 ms 19712 KB Output is correct
6 Correct 62 ms 8140 KB Output is correct
7 Correct 235 ms 21524 KB Output is correct
8 Correct 214 ms 21528 KB Output is correct
9 Correct 199 ms 20404 KB Output is correct
10 Correct 147 ms 19424 KB Output is correct
11 Correct 147 ms 19436 KB Output is correct
12 Correct 41 ms 7800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 223 ms 21876 KB Output is correct
2 Correct 231 ms 21932 KB Output is correct
3 Correct 217 ms 21856 KB Output is correct
4 Correct 154 ms 19744 KB Output is correct
5 Correct 163 ms 19712 KB Output is correct
6 Correct 62 ms 8140 KB Output is correct
7 Correct 235 ms 21524 KB Output is correct
8 Correct 214 ms 21528 KB Output is correct
9 Correct 199 ms 20404 KB Output is correct
10 Correct 147 ms 19424 KB Output is correct
11 Correct 147 ms 19436 KB Output is correct
12 Correct 41 ms 7800 KB Output is correct
13 Correct 232 ms 22228 KB Output is correct
14 Correct 238 ms 22244 KB Output is correct
15 Correct 232 ms 21900 KB Output is correct
16 Correct 161 ms 20112 KB Output is correct
17 Correct 160 ms 20044 KB Output is correct
18 Correct 61 ms 8096 KB Output is correct
19 Correct 229 ms 22364 KB Output is correct
20 Correct 241 ms 22348 KB Output is correct
21 Correct 220 ms 21612 KB Output is correct
22 Correct 143 ms 19648 KB Output is correct
23 Correct 145 ms 19544 KB Output is correct
24 Correct 50 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 8 ms 2176 KB Output is correct
8 Correct 8 ms 2112 KB Output is correct
9 Correct 7 ms 2112 KB Output is correct
10 Correct 5 ms 1368 KB Output is correct
11 Correct 5 ms 1388 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 7 ms 2180 KB Output is correct
14 Correct 7 ms 2132 KB Output is correct
15 Correct 7 ms 2132 KB Output is correct
16 Correct 4 ms 1364 KB Output is correct
17 Correct 4 ms 1364 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 223 ms 21876 KB Output is correct
20 Correct 231 ms 21932 KB Output is correct
21 Correct 217 ms 21856 KB Output is correct
22 Correct 154 ms 19744 KB Output is correct
23 Correct 163 ms 19712 KB Output is correct
24 Correct 62 ms 8140 KB Output is correct
25 Correct 235 ms 21524 KB Output is correct
26 Correct 214 ms 21528 KB Output is correct
27 Correct 199 ms 20404 KB Output is correct
28 Correct 147 ms 19424 KB Output is correct
29 Correct 147 ms 19436 KB Output is correct
30 Correct 41 ms 7800 KB Output is correct
31 Correct 232 ms 22228 KB Output is correct
32 Correct 238 ms 22244 KB Output is correct
33 Correct 232 ms 21900 KB Output is correct
34 Correct 161 ms 20112 KB Output is correct
35 Correct 160 ms 20044 KB Output is correct
36 Correct 61 ms 8096 KB Output is correct
37 Correct 229 ms 22364 KB Output is correct
38 Correct 241 ms 22348 KB Output is correct
39 Correct 220 ms 21612 KB Output is correct
40 Correct 143 ms 19648 KB Output is correct
41 Correct 145 ms 19544 KB Output is correct
42 Correct 50 ms 7680 KB Output is correct
43 Correct 571 ms 62096 KB Output is correct
44 Correct 563 ms 62088 KB Output is correct
45 Correct 580 ms 62036 KB Output is correct
46 Correct 230 ms 35500 KB Output is correct
47 Correct 231 ms 35496 KB Output is correct
48 Correct 54 ms 7920 KB Output is correct
49 Correct 517 ms 61892 KB Output is correct
50 Correct 658 ms 61972 KB Output is correct
51 Correct 466 ms 61920 KB Output is correct
52 Correct 254 ms 35264 KB Output is correct
53 Correct 201 ms 34540 KB Output is correct