Submission #1079768

# Submission time Handle Problem Language Result Execution time Memory
1079768 2024-08-29T01:06:06 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
281 ms 28456 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 6 ms 1148 KB Output is correct
8 Correct 5 ms 1212 KB Output is correct
9 Correct 5 ms 1116 KB Output is correct
10 Correct 5 ms 1204 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 1092 KB Output is correct
13 Correct 5 ms 1116 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 5 ms 1176 KB Output is correct
16 Correct 4 ms 992 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 25012 KB Output is correct
2 Correct 206 ms 25012 KB Output is correct
3 Correct 215 ms 25016 KB Output is correct
4 Correct 197 ms 24256 KB Output is correct
5 Correct 165 ms 24100 KB Output is correct
6 Correct 179 ms 23472 KB Output is correct
7 Correct 213 ms 24756 KB Output is correct
8 Correct 198 ms 24884 KB Output is correct
9 Correct 218 ms 26044 KB Output is correct
10 Correct 151 ms 23880 KB Output is correct
11 Correct 181 ms 24116 KB Output is correct
12 Correct 140 ms 22968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 25012 KB Output is correct
2 Correct 206 ms 25012 KB Output is correct
3 Correct 215 ms 25016 KB Output is correct
4 Correct 197 ms 24256 KB Output is correct
5 Correct 165 ms 24100 KB Output is correct
6 Correct 179 ms 23472 KB Output is correct
7 Correct 213 ms 24756 KB Output is correct
8 Correct 198 ms 24884 KB Output is correct
9 Correct 218 ms 26044 KB Output is correct
10 Correct 151 ms 23880 KB Output is correct
11 Correct 181 ms 24116 KB Output is correct
12 Correct 140 ms 22968 KB Output is correct
13 Correct 232 ms 25316 KB Output is correct
14 Correct 229 ms 25240 KB Output is correct
15 Correct 227 ms 25016 KB Output is correct
16 Correct 212 ms 24500 KB Output is correct
17 Correct 188 ms 24504 KB Output is correct
18 Correct 169 ms 23492 KB Output is correct
19 Correct 229 ms 25268 KB Output is correct
20 Correct 254 ms 25512 KB Output is correct
21 Correct 251 ms 25740 KB Output is correct
22 Correct 172 ms 23992 KB Output is correct
23 Correct 168 ms 23988 KB Output is correct
24 Correct 145 ms 23188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 6 ms 1148 KB Output is correct
8 Correct 5 ms 1212 KB Output is correct
9 Correct 5 ms 1116 KB Output is correct
10 Correct 5 ms 1204 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 4 ms 1092 KB Output is correct
13 Correct 5 ms 1116 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 5 ms 1176 KB Output is correct
16 Correct 4 ms 992 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 4 ms 988 KB Output is correct
19 Correct 209 ms 25012 KB Output is correct
20 Correct 206 ms 25012 KB Output is correct
21 Correct 215 ms 25016 KB Output is correct
22 Correct 197 ms 24256 KB Output is correct
23 Correct 165 ms 24100 KB Output is correct
24 Correct 179 ms 23472 KB Output is correct
25 Correct 213 ms 24756 KB Output is correct
26 Correct 198 ms 24884 KB Output is correct
27 Correct 218 ms 26044 KB Output is correct
28 Correct 151 ms 23880 KB Output is correct
29 Correct 181 ms 24116 KB Output is correct
30 Correct 140 ms 22968 KB Output is correct
31 Correct 232 ms 25316 KB Output is correct
32 Correct 229 ms 25240 KB Output is correct
33 Correct 227 ms 25016 KB Output is correct
34 Correct 212 ms 24500 KB Output is correct
35 Correct 188 ms 24504 KB Output is correct
36 Correct 169 ms 23492 KB Output is correct
37 Correct 229 ms 25268 KB Output is correct
38 Correct 254 ms 25512 KB Output is correct
39 Correct 251 ms 25740 KB Output is correct
40 Correct 172 ms 23992 KB Output is correct
41 Correct 168 ms 23988 KB Output is correct
42 Correct 145 ms 23188 KB Output is correct
43 Correct 265 ms 27388 KB Output is correct
44 Correct 281 ms 27280 KB Output is correct
45 Correct 233 ms 27348 KB Output is correct
46 Correct 221 ms 25780 KB Output is correct
47 Correct 196 ms 25776 KB Output is correct
48 Correct 175 ms 23220 KB Output is correct
49 Correct 248 ms 27060 KB Output is correct
50 Correct 247 ms 27320 KB Output is correct
51 Correct 268 ms 28456 KB Output is correct
52 Correct 182 ms 25432 KB Output is correct
53 Correct 170 ms 24732 KB Output is correct