답안 #374057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374057 2021-03-06T13:57:11 Z vaaven Examination (JOI19_examination) C++14
100 / 100
2750 ms 97428 KB
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <stack>
#include <iomanip>
#include <bitset>
#include <map>
#include <cassert>
#include <array>
#include <queue>
#include <cstring>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
 #define int long  long
      
using namespace std;
      
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
      
const int inf = 1e9 + 228;
const ll infll = 1e18;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-14;
      
      
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
//    freopen("d.in", "r", stdin);
//    freopen("d.out", "w", stdout);
}

struct node{
    int key, prior;
    int sz = 1;
    node *l = nullptr, *r = nullptr;
    node(int key): key(key){
        prior = rand();
    }
};

int get_sz(node *l){
    return (l ? l->sz : 0);
}

void upd(node *v){
    v->sz = 1 + get_sz(v->l) + get_sz(v->r);
}

pair<node*, node*> split(node *r, int x){
    if(!r)
        return {nullptr, nullptr};
    if(r -> key >= x){
        pair<node*, node*> mid = split(r->l, x);
        r->l = mid.second;
        upd(r);
        return {mid.first, r};
    } else{
        pair<node*, node*> mid = split(r->r, x);
        r->r = mid.first;
        upd(r);
        return {r, mid.second};
    }
}

node* merge(node *l, node *r){
    if(!l)
        return r;
    if(!r)
        return l;
    if(r->prior > l->prior){
        r->l = merge(l, r->l);
        upd(r);
        return r;
    } else{
        l->r = merge(l->r, r);
        upd(l);
        return l;
    }
}

int get(node *v, int x){
    pair<node*, node*> mid = split(v, x);
    int ans = get_sz(mid.second);
    v = merge(mid.first, mid.second);
    return ans;
}

void insert(node *&r, int x){
    node* nw = new node(x);
    pair<node*, node*> mid = split(r, x);
    r = merge(mid.first, merge(nw, mid.second));
}

const int maxn = 1e5 + 228;
node* t[maxn * 4];

void add(int v, int l, int r, int k, int k_new){
    insert(t[v], k_new);
    if(l == r)
        return;
    int mid = (l+r)/2;
    if(k <= mid)
        add(v*2, l, mid, k, k_new);
    else
        add(v*2+1, mid+1, r, k, k_new);
}

int get(int v, int l, int r, int ql, int qr, int x){
    if(ql <= l && r <= qr){
        return get(t[v], x);
    } else if(l > qr || ql > r){
        return 0;
    } else{
        int mid = (l+r)/2;
        return get(v*2, l, mid, ql, qr, x) + get(v*2+1, mid+1, r, ql, qr, x);
    }
}

struct post{
    int c, a, b, i;
    post(){}
    post(int a, int b, int c, int i): a(a), b(b), c(c), i(i){}
};

bool cmp1(pii a, pii b){
    return a.first + a.second > b.first + b.second;
}

bool cmp2(post a, post b){
    return a.c > b.c;
}

void solve(){
    int n, q;
    cin >> n >> q;
    vpii kek(n);
    vi lol;
    for(pii &i:kek){
        cin >> i.first >> i.second;
        lol.pb(i.first);
    }
    sort(all(kek), cmp1);
    vector<post> posts(q);
    for(int i=0; i<q; i++){
        int a, b, c;
        cin >> a >> b >> c;
        posts[i] = post(a, b, c, i);
    }
    sort(all(posts), cmp2);
    sort(all(lol));
    lol.resize(unique(all(lol)) - lol.begin());
    int pnt = 0;
    vi ans(q);
    for(post i:posts){
        while(pnt < n && kek[pnt].first + kek[pnt].second >= i.c){
//            cout << get_sz(t[1]) << endl;
            add(1, 0, maxn, lower_bound(all(lol), kek[pnt].first)-lol.begin(), kek[pnt].second);
//            cout << get_sz(t[1]) << endl;
            pnt++;
        }
        ans[i.i] = get(1, 0, maxn, lower_bound(all(lol), i.a)-lol.begin(), maxn, i.b);
    }
    for(int i:ans)
        cout << i << endl;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
=============
10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
 */

signed main(){
    fast_io();
//    srand(time(NULL));
    cout << fixed << setprecision(10);
    int q = 1;
//    cin >> q;
    while(q--)
        solve();
}

Compilation message

examination.cpp: In constructor 'post::post(long long int, long long int, long long int, long long int)':
examination.cpp:141:15: warning: 'post::b' will be initialized after [-Wreorder]
  141 |     int c, a, b, i;
      |               ^
examination.cpp:141:9: warning:   'long long int post::c' [-Wreorder]
  141 |     int c, a, b, i;
      |         ^
examination.cpp:143:5: warning:   when initialized here [-Wreorder]
  143 |     post(int a, int b, int c, int i): a(a), b(b), c(c), i(i){}
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 30 ms 3308 KB Output is correct
8 Correct 30 ms 3308 KB Output is correct
9 Correct 31 ms 3308 KB Output is correct
10 Correct 30 ms 3308 KB Output is correct
11 Correct 22 ms 3180 KB Output is correct
12 Correct 33 ms 3180 KB Output is correct
13 Correct 32 ms 3308 KB Output is correct
14 Correct 32 ms 3436 KB Output is correct
15 Correct 31 ms 3308 KB Output is correct
16 Correct 21 ms 3180 KB Output is correct
17 Correct 21 ms 3228 KB Output is correct
18 Correct 20 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2744 ms 94288 KB Output is correct
2 Correct 2722 ms 94184 KB Output is correct
3 Correct 2719 ms 94312 KB Output is correct
4 Correct 1878 ms 93532 KB Output is correct
5 Correct 1278 ms 92784 KB Output is correct
6 Correct 1795 ms 92296 KB Output is correct
7 Correct 2724 ms 94112 KB Output is correct
8 Correct 2249 ms 94216 KB Output is correct
9 Correct 2122 ms 94032 KB Output is correct
10 Correct 858 ms 93416 KB Output is correct
11 Correct 938 ms 93288 KB Output is correct
12 Correct 813 ms 92648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2744 ms 94288 KB Output is correct
2 Correct 2722 ms 94184 KB Output is correct
3 Correct 2719 ms 94312 KB Output is correct
4 Correct 1878 ms 93532 KB Output is correct
5 Correct 1278 ms 92784 KB Output is correct
6 Correct 1795 ms 92296 KB Output is correct
7 Correct 2724 ms 94112 KB Output is correct
8 Correct 2249 ms 94216 KB Output is correct
9 Correct 2122 ms 94032 KB Output is correct
10 Correct 858 ms 93416 KB Output is correct
11 Correct 938 ms 93288 KB Output is correct
12 Correct 813 ms 92648 KB Output is correct
13 Correct 2298 ms 94568 KB Output is correct
14 Correct 2688 ms 94500 KB Output is correct
15 Correct 2750 ms 94184 KB Output is correct
16 Correct 1636 ms 94036 KB Output is correct
17 Correct 1157 ms 93288 KB Output is correct
18 Correct 1823 ms 92208 KB Output is correct
19 Correct 2324 ms 94752 KB Output is correct
20 Correct 2522 ms 94708 KB Output is correct
21 Correct 2060 ms 94640 KB Output is correct
22 Correct 858 ms 93476 KB Output is correct
23 Correct 939 ms 93288 KB Output is correct
24 Correct 770 ms 92520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 30 ms 3308 KB Output is correct
8 Correct 30 ms 3308 KB Output is correct
9 Correct 31 ms 3308 KB Output is correct
10 Correct 30 ms 3308 KB Output is correct
11 Correct 22 ms 3180 KB Output is correct
12 Correct 33 ms 3180 KB Output is correct
13 Correct 32 ms 3308 KB Output is correct
14 Correct 32 ms 3436 KB Output is correct
15 Correct 31 ms 3308 KB Output is correct
16 Correct 21 ms 3180 KB Output is correct
17 Correct 21 ms 3228 KB Output is correct
18 Correct 20 ms 3180 KB Output is correct
19 Correct 2744 ms 94288 KB Output is correct
20 Correct 2722 ms 94184 KB Output is correct
21 Correct 2719 ms 94312 KB Output is correct
22 Correct 1878 ms 93532 KB Output is correct
23 Correct 1278 ms 92784 KB Output is correct
24 Correct 1795 ms 92296 KB Output is correct
25 Correct 2724 ms 94112 KB Output is correct
26 Correct 2249 ms 94216 KB Output is correct
27 Correct 2122 ms 94032 KB Output is correct
28 Correct 858 ms 93416 KB Output is correct
29 Correct 938 ms 93288 KB Output is correct
30 Correct 813 ms 92648 KB Output is correct
31 Correct 2298 ms 94568 KB Output is correct
32 Correct 2688 ms 94500 KB Output is correct
33 Correct 2750 ms 94184 KB Output is correct
34 Correct 1636 ms 94036 KB Output is correct
35 Correct 1157 ms 93288 KB Output is correct
36 Correct 1823 ms 92208 KB Output is correct
37 Correct 2324 ms 94752 KB Output is correct
38 Correct 2522 ms 94708 KB Output is correct
39 Correct 2060 ms 94640 KB Output is correct
40 Correct 858 ms 93476 KB Output is correct
41 Correct 939 ms 93288 KB Output is correct
42 Correct 770 ms 92520 KB Output is correct
43 Correct 2272 ms 97152 KB Output is correct
44 Correct 2213 ms 97260 KB Output is correct
45 Correct 2605 ms 97348 KB Output is correct
46 Correct 1584 ms 95796 KB Output is correct
47 Correct 1054 ms 94256 KB Output is correct
48 Correct 1682 ms 91892 KB Output is correct
49 Correct 2420 ms 97428 KB Output is correct
50 Correct 1971 ms 97252 KB Output is correct
51 Correct 1834 ms 97128 KB Output is correct
52 Correct 852 ms 94952 KB Output is correct
53 Correct 932 ms 94732 KB Output is correct