답안 #998289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998289 2024-06-13T14:08:51 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
256 ms 29896 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define el cout << '\n'
#define f1(i,n) for(ll i=1;i<=n;i++)
#define __file_name "F"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const ll maxn = 1e6+5, inf=1e18;

struct Pt{
    ll a, b, c;
    ll tp;
    Pt(){};
    Pt(ll _1, ll _2, ll _3, ll _4){
        a = _1; b = _2; c = _3;
        tp = _4;
    }
};

ll n,q,ans[maxn];
vector<Pt> v,tmp;

bool cmp(Pt x, Pt y){
    if(x.a == y.a){
        return x.tp < y.tp;
        if(x.b == y.b) return x.c > y.c;
        return x.b > y.b;
    }
    return x.a > y.a;
}

ordered_set S;

void cdq(ll l, ll r){
    if(l >= r) return;
    // cout << l << ' ' << r << endl;
    ll mid = (l+r)/2;
    cdq(l, mid);
    cdq(mid+1, r);
    ll p1 = l, p2 = mid+1;
    tmp.clear(); S.clear();
    while(p1 <= mid && p2 <= r){
        if(v[p1].b >= v[p2].b){
            if(v[p1].tp == 0){
                S.insert({v[p1].c, p1});
            }
            tmp.push_back(v[p1]);
            p1++;
        }else{
            if(v[p2].tp > 0){
                ans[v[p2].tp] += S.size() - S.order_of_key(make_pair(v[p2].c-1, inf));
            }
            tmp.push_back(v[p2]);
            p2++;
        }
    }
    while(p1 <= mid){
        tmp.push_back(v[p1]);
        p1++;
    }
    while(p2 <= r){
        if(v[p2].tp > 0){
            ans[v[p2].tp] += S.size() - S.order_of_key({v[p2].c-1, inf});
        }
        tmp.push_back(v[p2]);
        p2++;
    }
    for(ll i=l;i<=r;i++){
        v[i] = tmp[i-l];
    }

}

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

    if(fopen(__file_name ".inp", "r")){
        freopen(__file_name ".inp","r",stdin);
        freopen(__file_name ".out","w",stdout);
    }
    // code here
    cin >> n >> q;
    f1(i,n){
        ll s,t; cin >> s >> t;
        v.push_back(Pt(s,t,s+t,0));
    }
    f1(i,q){
        ll x, y, z; cin >> x >> y >> z;
        v.push_back(Pt(x, y, z, i));
    }
    sort(v.begin(), v.end(), cmp);
    cdq(0, v.size()-1);
    f1(i,q) cout << ans[i] << '\n';
    return 0;
}

/*
Code by: Nguyen Viet Trung Nhan
Cau Giay Secondary School
*/

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(__file_name ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(__file_name ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 5 ms 1156 KB Output is correct
10 Correct 5 ms 1116 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 992 KB Output is correct
13 Correct 5 ms 1116 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 4 ms 992 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 3 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 25404 KB Output is correct
2 Correct 202 ms 28604 KB Output is correct
3 Correct 204 ms 29116 KB Output is correct
4 Correct 202 ms 26548 KB Output is correct
5 Correct 162 ms 25784 KB Output is correct
6 Correct 167 ms 28348 KB Output is correct
7 Correct 214 ms 28600 KB Output is correct
8 Correct 192 ms 26268 KB Output is correct
9 Correct 208 ms 29360 KB Output is correct
10 Correct 150 ms 26804 KB Output is correct
11 Correct 164 ms 28608 KB Output is correct
12 Correct 137 ms 25524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 25404 KB Output is correct
2 Correct 202 ms 28604 KB Output is correct
3 Correct 204 ms 29116 KB Output is correct
4 Correct 202 ms 26548 KB Output is correct
5 Correct 162 ms 25784 KB Output is correct
6 Correct 167 ms 28348 KB Output is correct
7 Correct 214 ms 28600 KB Output is correct
8 Correct 192 ms 26268 KB Output is correct
9 Correct 208 ms 29360 KB Output is correct
10 Correct 150 ms 26804 KB Output is correct
11 Correct 164 ms 28608 KB Output is correct
12 Correct 137 ms 25524 KB Output is correct
13 Correct 224 ms 26164 KB Output is correct
14 Correct 212 ms 28660 KB Output is correct
15 Correct 200 ms 28852 KB Output is correct
16 Correct 208 ms 27836 KB Output is correct
17 Correct 179 ms 27316 KB Output is correct
18 Correct 170 ms 25784 KB Output is correct
19 Correct 226 ms 26296 KB Output is correct
20 Correct 223 ms 28088 KB Output is correct
21 Correct 256 ms 28596 KB Output is correct
22 Correct 156 ms 25644 KB Output is correct
23 Correct 162 ms 24988 KB Output is correct
24 Correct 137 ms 27064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 5 ms 1156 KB Output is correct
10 Correct 5 ms 1116 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 992 KB Output is correct
13 Correct 5 ms 1116 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 4 ms 992 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 3 ms 992 KB Output is correct
19 Correct 202 ms 25404 KB Output is correct
20 Correct 202 ms 28604 KB Output is correct
21 Correct 204 ms 29116 KB Output is correct
22 Correct 202 ms 26548 KB Output is correct
23 Correct 162 ms 25784 KB Output is correct
24 Correct 167 ms 28348 KB Output is correct
25 Correct 214 ms 28600 KB Output is correct
26 Correct 192 ms 26268 KB Output is correct
27 Correct 208 ms 29360 KB Output is correct
28 Correct 150 ms 26804 KB Output is correct
29 Correct 164 ms 28608 KB Output is correct
30 Correct 137 ms 25524 KB Output is correct
31 Correct 224 ms 26164 KB Output is correct
32 Correct 212 ms 28660 KB Output is correct
33 Correct 200 ms 28852 KB Output is correct
34 Correct 208 ms 27836 KB Output is correct
35 Correct 179 ms 27316 KB Output is correct
36 Correct 170 ms 25784 KB Output is correct
37 Correct 226 ms 26296 KB Output is correct
38 Correct 223 ms 28088 KB Output is correct
39 Correct 256 ms 28596 KB Output is correct
40 Correct 156 ms 25644 KB Output is correct
41 Correct 162 ms 24988 KB Output is correct
42 Correct 137 ms 27064 KB Output is correct
43 Correct 228 ms 28936 KB Output is correct
44 Correct 235 ms 29112 KB Output is correct
45 Correct 222 ms 27832 KB Output is correct
46 Correct 213 ms 27060 KB Output is correct
47 Correct 215 ms 29896 KB Output is correct
48 Correct 179 ms 26552 KB Output is correct
49 Correct 239 ms 29112 KB Output is correct
50 Correct 233 ms 29612 KB Output is correct
51 Correct 248 ms 29296 KB Output is correct
52 Correct 188 ms 29112 KB Output is correct
53 Correct 163 ms 25676 KB Output is correct