답안 #232011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232011 2020-05-15T17:14:20 Z Charis02 Examination (JOI19_examination) C++14
100 / 100
1292 ms 75640 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

struct student
{
    ll a;
    ll b;
    ll c;
    ll id;

    bool operator <(const student &s)const
    {
        return c < s.c;
    }
};

ll n,q,cnt;
student ar[N];
student queries[N];
ll seg[4*N][2];
map < ll,ll > mapper;
set < ll > values;
ll ans[N];

void update(ll low,ll high,ll pos,ll slow,ll id)
{
    if(low == slow && high==slow)
    {
        seg[pos][id]++;
        return;
    }
    if(low>slow||high<slow)
        return;

    update(low,mid,pos*2+1,slow,id);
    update(mid+1,high,pos*2+2,slow,id);

    seg[pos][id] = seg[pos*2+1][id]+seg[pos*2+2][id];
    return;
}

ll query(ll low,ll high,ll pos,ll slow,ll shigh,ll id)
{
    if(low>=slow&&high<=shigh)
        return seg[pos][id];
    if(high<slow||low>shigh)
        return 0;

    return query(low,mid,pos*2+1,slow,shigh,id)+query(mid+1,high,pos*2+2,slow,shigh,id);
}

bool by_b(const student &a,const student &b)
{
    return a.b < b.b;
}

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

    cin >> n >> q;

    rep(i,0,n)
    {
        cin >> ar[i].a >> ar[i].b;
        ar[i].c = ar[i].a+ar[i].b;
        values.insert(ar[i].a);
        values.insert(ar[i].b);
    }

    sort(ar,ar+n);
    reverse(ar,ar+n);

    rep(i,0,q)
    {
        cin >> queries[i].a >> queries[i].b >> queries[i].c;
        queries[i].id=i;
        values.insert(queries[i].a);
        values.insert(queries[i].b-1);
    }

    for(set < ll >::iterator it = values.begin();it!=values.end();it++)
        mapper[(*it)]=cnt++;

    sort(queries,queries+q);
    reverse(queries,queries+q);

    ll cur = 0;

    rep(i,0,q)
    {
        if(queries[i].a + queries[i].b > queries[i].c)
            continue;

        while(cur < n && ar[cur].c >= queries[i].c)
        {
            update(0,cnt,0,mapper[ar[cur].a],0);
            update(0,cnt,0,mapper[ar[cur].b],1);
            cur++;
        }

        ll blue = query(0,cnt,0,mapper[queries[i].a],cnt,0);
        ll orange = query(0,cnt,0,0,mapper[queries[i].b-1],1);

   //     cerr << "here " << queries[i].id << " " << cur << " " << blue << " " << orange << endl;
        ans[queries[i].id] = blue-orange;
    }

    memset(seg,0,sizeof seg);
    sort(queries,queries+q,by_b);
    reverse(queries,queries+q);
    sort(ar,ar+n,by_b);
    reverse(ar,ar+n);

    cur = 0;

    rep(i,0,q)
    {
        if(queries[i].a+queries[i].b <= queries[i].c)
            continue;

        while(cur < n && ar[cur].b >= queries[i].b)
        {
            update(0,cnt,0,mapper[ar[cur].a],0);
            cur++;
        }

        ans[queries[i].id] = query(0,cnt,0,mapper[queries[i].a],cnt,0);
    }

    rep(i,0,q)
        cout << ans[i] << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 19200 KB Output is correct
2 Correct 14 ms 19200 KB Output is correct
3 Correct 14 ms 19200 KB Output is correct
4 Correct 14 ms 19200 KB Output is correct
5 Correct 14 ms 19200 KB Output is correct
6 Correct 14 ms 19200 KB Output is correct
7 Correct 28 ms 20864 KB Output is correct
8 Correct 28 ms 20864 KB Output is correct
9 Correct 29 ms 20864 KB Output is correct
10 Correct 24 ms 20096 KB Output is correct
11 Correct 23 ms 20096 KB Output is correct
12 Correct 17 ms 19456 KB Output is correct
13 Correct 25 ms 20864 KB Output is correct
14 Correct 26 ms 20856 KB Output is correct
15 Correct 26 ms 20864 KB Output is correct
16 Correct 20 ms 20096 KB Output is correct
17 Correct 22 ms 20224 KB Output is correct
18 Correct 16 ms 19456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 37496 KB Output is correct
2 Correct 433 ms 40056 KB Output is correct
3 Correct 437 ms 40056 KB Output is correct
4 Correct 314 ms 38008 KB Output is correct
5 Correct 229 ms 38008 KB Output is correct
6 Correct 102 ms 27768 KB Output is correct
7 Correct 385 ms 39800 KB Output is correct
8 Correct 400 ms 39672 KB Output is correct
9 Correct 342 ms 38720 KB Output is correct
10 Correct 228 ms 37752 KB Output is correct
11 Correct 313 ms 37820 KB Output is correct
12 Correct 79 ms 27388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 37496 KB Output is correct
2 Correct 433 ms 40056 KB Output is correct
3 Correct 437 ms 40056 KB Output is correct
4 Correct 314 ms 38008 KB Output is correct
5 Correct 229 ms 38008 KB Output is correct
6 Correct 102 ms 27768 KB Output is correct
7 Correct 385 ms 39800 KB Output is correct
8 Correct 400 ms 39672 KB Output is correct
9 Correct 342 ms 38720 KB Output is correct
10 Correct 228 ms 37752 KB Output is correct
11 Correct 313 ms 37820 KB Output is correct
12 Correct 79 ms 27388 KB Output is correct
13 Correct 644 ms 40568 KB Output is correct
14 Correct 544 ms 40440 KB Output is correct
15 Correct 419 ms 40184 KB Output is correct
16 Correct 388 ms 38392 KB Output is correct
17 Correct 326 ms 38444 KB Output is correct
18 Correct 105 ms 27768 KB Output is correct
19 Correct 594 ms 40620 KB Output is correct
20 Correct 625 ms 40440 KB Output is correct
21 Correct 594 ms 39932 KB Output is correct
22 Correct 214 ms 37880 KB Output is correct
23 Correct 345 ms 37880 KB Output is correct
24 Correct 82 ms 27384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 19200 KB Output is correct
2 Correct 14 ms 19200 KB Output is correct
3 Correct 14 ms 19200 KB Output is correct
4 Correct 14 ms 19200 KB Output is correct
5 Correct 14 ms 19200 KB Output is correct
6 Correct 14 ms 19200 KB Output is correct
7 Correct 28 ms 20864 KB Output is correct
8 Correct 28 ms 20864 KB Output is correct
9 Correct 29 ms 20864 KB Output is correct
10 Correct 24 ms 20096 KB Output is correct
11 Correct 23 ms 20096 KB Output is correct
12 Correct 17 ms 19456 KB Output is correct
13 Correct 25 ms 20864 KB Output is correct
14 Correct 26 ms 20856 KB Output is correct
15 Correct 26 ms 20864 KB Output is correct
16 Correct 20 ms 20096 KB Output is correct
17 Correct 22 ms 20224 KB Output is correct
18 Correct 16 ms 19456 KB Output is correct
19 Correct 428 ms 37496 KB Output is correct
20 Correct 433 ms 40056 KB Output is correct
21 Correct 437 ms 40056 KB Output is correct
22 Correct 314 ms 38008 KB Output is correct
23 Correct 229 ms 38008 KB Output is correct
24 Correct 102 ms 27768 KB Output is correct
25 Correct 385 ms 39800 KB Output is correct
26 Correct 400 ms 39672 KB Output is correct
27 Correct 342 ms 38720 KB Output is correct
28 Correct 228 ms 37752 KB Output is correct
29 Correct 313 ms 37820 KB Output is correct
30 Correct 79 ms 27388 KB Output is correct
31 Correct 644 ms 40568 KB Output is correct
32 Correct 544 ms 40440 KB Output is correct
33 Correct 419 ms 40184 KB Output is correct
34 Correct 388 ms 38392 KB Output is correct
35 Correct 326 ms 38444 KB Output is correct
36 Correct 105 ms 27768 KB Output is correct
37 Correct 594 ms 40620 KB Output is correct
38 Correct 625 ms 40440 KB Output is correct
39 Correct 594 ms 39932 KB Output is correct
40 Correct 214 ms 37880 KB Output is correct
41 Correct 345 ms 37880 KB Output is correct
42 Correct 82 ms 27384 KB Output is correct
43 Correct 1292 ms 75620 KB Output is correct
44 Correct 1244 ms 75596 KB Output is correct
45 Correct 1193 ms 75384 KB Output is correct
46 Correct 566 ms 52088 KB Output is correct
47 Correct 460 ms 51992 KB Output is correct
48 Correct 113 ms 27640 KB Output is correct
49 Correct 1235 ms 75516 KB Output is correct
50 Correct 1232 ms 75640 KB Output is correct
51 Correct 1182 ms 75480 KB Output is correct
52 Correct 434 ms 51964 KB Output is correct
53 Correct 406 ms 51064 KB Output is correct