답안 #1091000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091000 2024-09-19T12:23:03 Z akim9905 Examination (JOI19_examination) C++17
100 / 100
406 ms 20068 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;

const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 202020; // PLZ CHK!

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag,tree_order_statistics_node_update>

typedef array<int,5> arr;

int N,Q;
vector<arr> A;
ll ans[MAX];

void dnc(int l, int r) {
    if (l==r) return;

    int m=(l+r)>>1;
    dnc(l,m), dnc(m+1,r);
    vector<arr> le,ri;
    for (int i=l; i<=m; i++) le.pb(A[i]);
    for (int i=m+1; i<=r; i++) ri.pb(A[i]);

    sort(all(le),[](auto a, auto b){return a[1]>b[1];});
    sort(all(ri),[](auto a, auto b){return a[1]>b[1];});

    ordered_set os;
    int i=0; 
    for (auto [x,y,z,q,idx]:ri) {
        while (i<sz(le) && le[i][1]>=y) {
            if (le[i][3]==0) os.insert({le[i][2],le[i][4]});
            i++;
        }

        if (q) {
            ll t=sz(os)-os.order_of_key({z,-INF});
            ans[idx]+=t;
        }
    }
}

int main() {
    fio();
    cin>>N>>Q;
    for (int i=0; i<N; i++) {
        int s,t; cin>>s>>t;
        A.pb({s,t,s+t,0,i});
    }
    for (int i=0; i<Q; i++) {
        int x,y,z; cin>>x>>y>>z;
        A.pb({x,y,z,1,i});
    }

    sort(all(A),[](auto a, auto b){
        if (a[0]==b[0]) return a[3]<b[3];
        return a[0]>b[0];
    });

    dnc(0,N+Q-1);

    for (int i=0; i<Q; i++) cout<<ans[i]<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 8 ms 860 KB Output is correct
8 Correct 8 ms 860 KB Output is correct
9 Correct 8 ms 908 KB Output is correct
10 Correct 7 ms 828 KB Output is correct
11 Correct 7 ms 852 KB Output is correct
12 Correct 7 ms 828 KB Output is correct
13 Correct 7 ms 872 KB Output is correct
14 Correct 7 ms 828 KB Output is correct
15 Correct 8 ms 828 KB Output is correct
16 Correct 7 ms 828 KB Output is correct
17 Correct 6 ms 828 KB Output is correct
18 Correct 5 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 15236 KB Output is correct
2 Correct 371 ms 15284 KB Output is correct
3 Correct 372 ms 15076 KB Output is correct
4 Correct 316 ms 14008 KB Output is correct
5 Correct 330 ms 14616 KB Output is correct
6 Correct 292 ms 13508 KB Output is correct
7 Correct 395 ms 17616 KB Output is correct
8 Correct 353 ms 15024 KB Output is correct
9 Correct 372 ms 17584 KB Output is correct
10 Correct 316 ms 14300 KB Output is correct
11 Correct 272 ms 13904 KB Output is correct
12 Correct 241 ms 14640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 15236 KB Output is correct
2 Correct 371 ms 15284 KB Output is correct
3 Correct 372 ms 15076 KB Output is correct
4 Correct 316 ms 14008 KB Output is correct
5 Correct 330 ms 14616 KB Output is correct
6 Correct 292 ms 13508 KB Output is correct
7 Correct 395 ms 17616 KB Output is correct
8 Correct 353 ms 15024 KB Output is correct
9 Correct 372 ms 17584 KB Output is correct
10 Correct 316 ms 14300 KB Output is correct
11 Correct 272 ms 13904 KB Output is correct
12 Correct 241 ms 14640 KB Output is correct
13 Correct 398 ms 15536 KB Output is correct
14 Correct 364 ms 15576 KB Output is correct
15 Correct 363 ms 15288 KB Output is correct
16 Correct 331 ms 14772 KB Output is correct
17 Correct 336 ms 15144 KB Output is correct
18 Correct 315 ms 14008 KB Output is correct
19 Correct 381 ms 15792 KB Output is correct
20 Correct 372 ms 15536 KB Output is correct
21 Correct 394 ms 16680 KB Output is correct
22 Correct 318 ms 14396 KB Output is correct
23 Correct 260 ms 13760 KB Output is correct
24 Correct 239 ms 14776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 8 ms 860 KB Output is correct
8 Correct 8 ms 860 KB Output is correct
9 Correct 8 ms 908 KB Output is correct
10 Correct 7 ms 828 KB Output is correct
11 Correct 7 ms 852 KB Output is correct
12 Correct 7 ms 828 KB Output is correct
13 Correct 7 ms 872 KB Output is correct
14 Correct 7 ms 828 KB Output is correct
15 Correct 8 ms 828 KB Output is correct
16 Correct 7 ms 828 KB Output is correct
17 Correct 6 ms 828 KB Output is correct
18 Correct 5 ms 780 KB Output is correct
19 Correct 379 ms 15236 KB Output is correct
20 Correct 371 ms 15284 KB Output is correct
21 Correct 372 ms 15076 KB Output is correct
22 Correct 316 ms 14008 KB Output is correct
23 Correct 330 ms 14616 KB Output is correct
24 Correct 292 ms 13508 KB Output is correct
25 Correct 395 ms 17616 KB Output is correct
26 Correct 353 ms 15024 KB Output is correct
27 Correct 372 ms 17584 KB Output is correct
28 Correct 316 ms 14300 KB Output is correct
29 Correct 272 ms 13904 KB Output is correct
30 Correct 241 ms 14640 KB Output is correct
31 Correct 398 ms 15536 KB Output is correct
32 Correct 364 ms 15576 KB Output is correct
33 Correct 363 ms 15288 KB Output is correct
34 Correct 331 ms 14772 KB Output is correct
35 Correct 336 ms 15144 KB Output is correct
36 Correct 315 ms 14008 KB Output is correct
37 Correct 381 ms 15792 KB Output is correct
38 Correct 372 ms 15536 KB Output is correct
39 Correct 394 ms 16680 KB Output is correct
40 Correct 318 ms 14396 KB Output is correct
41 Correct 260 ms 13760 KB Output is correct
42 Correct 239 ms 14776 KB Output is correct
43 Correct 388 ms 18100 KB Output is correct
44 Correct 386 ms 17548 KB Output is correct
45 Correct 373 ms 17592 KB Output is correct
46 Correct 324 ms 15468 KB Output is correct
47 Correct 385 ms 16312 KB Output is correct
48 Correct 294 ms 14060 KB Output is correct
49 Correct 394 ms 20068 KB Output is correct
50 Correct 379 ms 18152 KB Output is correct
51 Correct 406 ms 19816 KB Output is correct
52 Correct 360 ms 16308 KB Output is correct
53 Correct 285 ms 14720 KB Output is correct