Submission #966417

# Submission time Handle Problem Language Result Execution time Memory
966417 2024-04-19T20:27:29 Z oviyan_gandhi Examination (JOI19_examination) C++17
0 / 100
1830 ms 21320 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef tree<pii, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define N 100000
#define S 320
pii s[N]; // {s, t}

struct Query {
    int x, y, c, i;
    bool operator < (const Query &o) const {
        if (x/S != o.x/S) return x < o.x;
        return y < o.y;
    }
};
Query qu[N];
int ans[N];

set<pii> st; // {t, i}
oset sc; // {s + t, i}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++)
        cin >> s[i].first >> s[i].second;
    sort(s, s+n);
    for (int i = 0; i < q; i++){
        cin >> qu[i].x >> qu[i].y >> qu[i].c;
        qu[i].i = i;
        qu[i].x = lower_bound(s, s+n, make_pair(qu[i].x, 0LL)) - s;
    }
    sort(qu, qu+q);
    int idx = n;
    for (int i = 0; i < q; i++){
        while (idx && idx-1 >= qu[i].x){
            idx--;
            st.insert({s[idx].second, idx});
            sc.insert({s[idx].first + s[idx].second, idx});
        }
        while (idx < qu[i].x){
            auto it = st.find({s[idx].second, idx});
            if (it != st.end()){
                st.erase(it);
                sc.erase({s[idx].first + s[idx].second, idx});
            }
            idx++;
        }
        while (!st.empty() && st.begin()->first < qu[i].y){
            int j = st.begin()->second;
            st.erase(st.begin());
            sc.erase({s[j].first + s[j].second, j});
        }
        ans[qu[i].i] = sc.size() - sc.order_of_key({qu[i].c, 0});
    }
    for (int i = 0; i < q; i++)
        cout << ans[i] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 52 ms 5076 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1830 ms 21320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1830 ms 21320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Incorrect 52 ms 5076 KB Output isn't correct
8 Halted 0 ms 0 KB -