답안 #217305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217305 2020-03-29T11:45:15 Z my99n Examination (JOI19_examination) C++14
100 / 100
418 ms 16748 KB
#include<bits/stdc++.h>
using namespace std;

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

auto sortall = [](E&a, E&b) {
    if (a.a != b.a) return a.a > b.a;
    if (a.b != b.b) return a.b > b.b;
    if (a.c != b.c) return a.c > b.c;
    return a.t > b.t;
};
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());
    sum.resize(unique(sum.begin(), sum.end())-sum.begin());
    for (int i = 1; i <= cnt; i++) a[i].c = coord(a[i].c);

    sort(a+1, a+cnt+1, sortall);
    CDQ(1, cnt);
    for (int i = 0; i < q; i++) cout << ans[i] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 416 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 13 ms 896 KB Output is correct
8 Correct 13 ms 896 KB Output is correct
9 Correct 14 ms 896 KB Output is correct
10 Correct 11 ms 760 KB Output is correct
11 Correct 12 ms 896 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 12 ms 896 KB Output is correct
14 Correct 12 ms 896 KB Output is correct
15 Correct 12 ms 896 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 11 ms 768 KB Output is correct
18 Correct 9 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 13808 KB Output is correct
2 Correct 378 ms 13552 KB Output is correct
3 Correct 374 ms 13724 KB Output is correct
4 Correct 264 ms 12784 KB Output is correct
5 Correct 288 ms 12912 KB Output is correct
6 Correct 171 ms 11756 KB Output is correct
7 Correct 362 ms 13872 KB Output is correct
8 Correct 373 ms 13480 KB Output is correct
9 Correct 357 ms 13808 KB Output is correct
10 Correct 227 ms 12400 KB Output is correct
11 Correct 230 ms 12528 KB Output is correct
12 Correct 153 ms 11504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 13808 KB Output is correct
2 Correct 378 ms 13552 KB Output is correct
3 Correct 374 ms 13724 KB Output is correct
4 Correct 264 ms 12784 KB Output is correct
5 Correct 288 ms 12912 KB Output is correct
6 Correct 171 ms 11756 KB Output is correct
7 Correct 362 ms 13872 KB Output is correct
8 Correct 373 ms 13480 KB Output is correct
9 Correct 357 ms 13808 KB Output is correct
10 Correct 227 ms 12400 KB Output is correct
11 Correct 230 ms 12528 KB Output is correct
12 Correct 153 ms 11504 KB Output is correct
13 Correct 398 ms 14188 KB Output is correct
14 Correct 405 ms 14192 KB Output is correct
15 Correct 372 ms 13548 KB Output is correct
16 Correct 285 ms 13388 KB Output is correct
17 Correct 304 ms 13040 KB Output is correct
18 Correct 179 ms 11756 KB Output is correct
19 Correct 404 ms 14064 KB Output is correct
20 Correct 410 ms 14188 KB Output is correct
21 Correct 383 ms 14320 KB Output is correct
22 Correct 227 ms 12400 KB Output is correct
23 Correct 232 ms 12656 KB Output is correct
24 Correct 151 ms 11376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 416 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 13 ms 896 KB Output is correct
8 Correct 13 ms 896 KB Output is correct
9 Correct 14 ms 896 KB Output is correct
10 Correct 11 ms 760 KB Output is correct
11 Correct 12 ms 896 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 12 ms 896 KB Output is correct
14 Correct 12 ms 896 KB Output is correct
15 Correct 12 ms 896 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 11 ms 768 KB Output is correct
18 Correct 9 ms 768 KB Output is correct
19 Correct 382 ms 13808 KB Output is correct
20 Correct 378 ms 13552 KB Output is correct
21 Correct 374 ms 13724 KB Output is correct
22 Correct 264 ms 12784 KB Output is correct
23 Correct 288 ms 12912 KB Output is correct
24 Correct 171 ms 11756 KB Output is correct
25 Correct 362 ms 13872 KB Output is correct
26 Correct 373 ms 13480 KB Output is correct
27 Correct 357 ms 13808 KB Output is correct
28 Correct 227 ms 12400 KB Output is correct
29 Correct 230 ms 12528 KB Output is correct
30 Correct 153 ms 11504 KB Output is correct
31 Correct 398 ms 14188 KB Output is correct
32 Correct 405 ms 14192 KB Output is correct
33 Correct 372 ms 13548 KB Output is correct
34 Correct 285 ms 13388 KB Output is correct
35 Correct 304 ms 13040 KB Output is correct
36 Correct 179 ms 11756 KB Output is correct
37 Correct 404 ms 14064 KB Output is correct
38 Correct 410 ms 14188 KB Output is correct
39 Correct 383 ms 14320 KB Output is correct
40 Correct 227 ms 12400 KB Output is correct
41 Correct 232 ms 12656 KB Output is correct
42 Correct 151 ms 11376 KB Output is correct
43 Correct 418 ms 16624 KB Output is correct
44 Correct 414 ms 16496 KB Output is correct
45 Correct 414 ms 16384 KB Output is correct
46 Correct 292 ms 14836 KB Output is correct
47 Correct 315 ms 14960 KB Output is correct
48 Correct 191 ms 11632 KB Output is correct
49 Correct 410 ms 16748 KB Output is correct
50 Correct 403 ms 16240 KB Output is correct
51 Correct 408 ms 16620 KB Output is correct
52 Correct 262 ms 14448 KB Output is correct
53 Correct 251 ms 13476 KB Output is correct