Submission #217289

# Submission time Handle Problem Language Result Execution time Memory
217289 2020-03-29T11:10:55 Z my99n Examination (JOI19_examination) C++14
0 / 100
374 ms 11280 KB
#include<bits/stdc++.h>
using namespace std;

struct E { long long a, b, c, t, i; } a[200100];
long long ans[100100];

auto sorta = [](E&a, E&b) {return a.a > b.a;};
auto sortb= [](E&a, E&b) {return a.b > b.b;};

int fw[200100]; 
stack<pair<int,int>> h;
void add (int a, int v) { h.push({a, v}); for (int i = a; i > 0; i-=(i&-i)) fw[i]+=v; }
long long query (int a) {long long ans = 0; for (int i = a; i <= 200000; i+=(i&-i)) ans+=fw[i]; return ans;}
void clear () { while (!h.empty()) {auto t = h.top(); h.pop(); add(t.first, -t.second); h.pop();}}

vector<int> sum;
int coord (int x) { return int(lower_bound(sum.begin(), sum.end() ,x) - sum.begin() + 1); }

void CDQ (int l, int r) {
    if (l == r) return;
    int m = (l+r)/2;
    CDQ(l, m); CDQ(m+1, r);
    sort(a+l, a+m+1, sortb); sort(a+m+1, a+r+1, sortb);
    int i = l, j = m+1;
    clear();
    while (i <= m and j <= r) {
        if (a[i].b >= a[j].b) {
            if (a[i].t == 0) {i++; continue;} 
            add(a[i].c, 1);
            i++;
        }
        else {
            if (a[j].i == -1) { j++; continue; }
            ans[a[j].i] += query(a[j].c); 
            j++;
        }
    }
    while (j <= r) {
        if (a[j].i == -1) { j++; continue; }
        ans[a[j].i] += query(a[j].c); 
        j++;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        long long s, t; cin >> s >> t;
        a[++cnt] = {s+1, t+1, s+t+1, 1, -1};
        sum.push_back(s+t+1);
    }
    for (int i = 0; i < q; i++) {
        long long x, y, z; cin >> x >> y >> z;
        a[++cnt] = {x+1, y+1, z+1, 0, i};
        sum.push_back(z+1);
    }
    sort(sum.begin(), sum.end());
    for (int i = 1; i <= cnt; i++) a[i].c = coord(a[i].c);
    
    sort(a+1, a+cnt+1, sorta);
    CDQ(1, cnt);
    for (int i = 0; i < q; i++) cout << ans[i] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 13 ms 896 KB Output is correct
10 Correct 11 ms 768 KB Output is correct
11 Incorrect 12 ms 896 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 374 ms 11280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 374 ms 11280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 12 ms 896 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 13 ms 896 KB Output is correct
10 Correct 11 ms 768 KB Output is correct
11 Incorrect 12 ms 896 KB Output isn't correct
12 Halted 0 ms 0 KB -