답안 #1079861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079861 2024-08-29T02:45:22 Z KhoaDuy Examination (JOI19_examination) C++14
100 / 100
579 ms 37380 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct cube{
    int a,b,c,idx;
};
const int MAXN=1e5;
int ans[MAXN]={0};
int bit[2*MAXN+1]={0};
void update(int i,int x){
    for(;i<=2*MAXN;i+=(i&(-i))){
        bit[i]+=x;
    }
}
int pre(int i){
    int curr=0;
    for(;i;i-=(i&(-i))){
        curr+=bit[i];
    }
    return curr;
}
int query(int l,int r){
    return pre(r)-pre(l-1);
}
bool cmp(cube &a,cube &b){
    return (a.b>b.b);
}
bool cmp2(cube &a,cube &b){
    if(a.a!=b.a){
        return (a.a<b.a);
    }
    if(a.b!=b.b){
        return (a.b<b.b);
    }
    if(a.c!=b.c){
        return (a.c<b.c);
    }
    if(a.idx!=b.idx){
        return (a.idx>b.idx);
    }
}
void dnc(vector<cube> &v){
    if(v.size()<=1){
        return;
    }
    int mid=(v.size()>>1);
    vector<cube> v1,v2;
    for(int i=0;i<mid;i++){
        v1.push_back(v[i]);
    }
    for(int i=mid;i<v.size();i++){
        v2.push_back(v[i]);
    }
    dnc(v1),dnc(v2);
    sort(v.begin(),v.end(),cmp);
    /*cout << "GOT" << endl;
    cout << "V1: " << endl;
    for(int i=0;i<v1.size();i++){
        cout << v1[i].a << ' ' << v1[i].b << ' ' << v1[i].c << ' ' << v1[i].idx << endl;
    }
    cout << "V2: " << endl;
    for(int i=0;i<v2.size();i++){
        cout << v2[i].a << ' ' << v2[i].b << ' ' << v2[i].c << ' ' << v2[i].idx << endl;
    }*/
    int ptr=0;
    for(int i=0;i<v2.size();i++){
        while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
            if(v1[ptr].idx!=-1){
                ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
            }
            ptr++;
        }
        if(v2[i].idx==-1){
            update(v2[i].c,1);
        }
    }
    while(ptr<v1.size()){
        if(v1[ptr].idx!=-1){
            ans[v1[ptr].idx]+=query(v1[ptr].c,2*MAXN);
        }
        ptr++;
    }
    for(int i=0;i<v2.size();i++){
        if(v2[i].idx==-1){
            update(v2[i].c,-1);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n >> q;
    vector<cube> v;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int s,t;
        cin >> s >> t;
        v.push_back({s,t,s+t,-1});
        mp[s+t]=1;
    }
    for(int i=0;i<q;i++){
        int x,y,z;
        cin >> x >> y >> z;
        v.push_back({x,y,z,i});
        mp[z]=1;
    }
    int idx=1;
    for(pair<const int,int> &x:mp){
        x.second=idx;
        idx++;
    }
    for(int i=0;i<v.size();i++){
        v[i].c=mp[v[i].c];
    }
    for(int i=0;i<v.size();i++){
    //    cout << v[i].a << ' ' << v[i].b << ' ' << v[i].c << ' ' << v[i].idx << endl;
    }
    sort(v.begin(),v.end(),cmp2);
    dnc(v);
    for(int i=0;i<q;i++){
        cout << ans[i] << endl;
    }
}

Compilation message

examination.cpp: In function 'void dnc(std::vector<cube>&)':
examination.cpp:52:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=mid;i<v.size();i++){
      |                   ~^~~~~~~~~
examination.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<v2.size();i++){
      |                 ~^~~~~~~~~~
examination.cpp:68:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         while(ptr<v1.size()&&v1[ptr].b>v2[i].b){
      |               ~~~^~~~~~~~~~
examination.cpp:78:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     while(ptr<v1.size()){
      |           ~~~^~~~~~~~~~
examination.cpp:84:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int i=0;i<v2.size();i++){
      |                 ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:114:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
examination.cpp:117:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<cube>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
examination.cpp: In function 'bool cmp2(cube&, cube&)':
examination.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 10 ms 1496 KB Output is correct
8 Correct 9 ms 1496 KB Output is correct
9 Correct 10 ms 1556 KB Output is correct
10 Correct 8 ms 1496 KB Output is correct
11 Correct 8 ms 3544 KB Output is correct
12 Correct 5 ms 3036 KB Output is correct
13 Correct 8 ms 3452 KB Output is correct
14 Correct 8 ms 3288 KB Output is correct
15 Correct 9 ms 3132 KB Output is correct
16 Correct 8 ms 3284 KB Output is correct
17 Correct 7 ms 3544 KB Output is correct
18 Correct 5 ms 1168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 408 ms 29600 KB Output is correct
2 Correct 406 ms 27444 KB Output is correct
3 Correct 424 ms 29616 KB Output is correct
4 Correct 315 ms 30124 KB Output is correct
5 Correct 308 ms 30640 KB Output is correct
6 Correct 213 ms 22456 KB Output is correct
7 Correct 389 ms 26680 KB Output is correct
8 Correct 396 ms 28200 KB Output is correct
9 Correct 387 ms 27568 KB Output is correct
10 Correct 280 ms 27768 KB Output is correct
11 Correct 260 ms 29360 KB Output is correct
12 Correct 198 ms 21172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 408 ms 29600 KB Output is correct
2 Correct 406 ms 27444 KB Output is correct
3 Correct 424 ms 29616 KB Output is correct
4 Correct 315 ms 30124 KB Output is correct
5 Correct 308 ms 30640 KB Output is correct
6 Correct 213 ms 22456 KB Output is correct
7 Correct 389 ms 26680 KB Output is correct
8 Correct 396 ms 28200 KB Output is correct
9 Correct 387 ms 27568 KB Output is correct
10 Correct 280 ms 27768 KB Output is correct
11 Correct 260 ms 29360 KB Output is correct
12 Correct 198 ms 21172 KB Output is correct
13 Correct 489 ms 32176 KB Output is correct
14 Correct 464 ms 33456 KB Output is correct
15 Correct 414 ms 27380 KB Output is correct
16 Correct 379 ms 28832 KB Output is correct
17 Correct 361 ms 30260 KB Output is correct
18 Correct 213 ms 21688 KB Output is correct
19 Correct 466 ms 31944 KB Output is correct
20 Correct 477 ms 32488 KB Output is correct
21 Correct 476 ms 32288 KB Output is correct
22 Correct 304 ms 29612 KB Output is correct
23 Correct 266 ms 26352 KB Output is correct
24 Correct 199 ms 22708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 10 ms 1496 KB Output is correct
8 Correct 9 ms 1496 KB Output is correct
9 Correct 10 ms 1556 KB Output is correct
10 Correct 8 ms 1496 KB Output is correct
11 Correct 8 ms 3544 KB Output is correct
12 Correct 5 ms 3036 KB Output is correct
13 Correct 8 ms 3452 KB Output is correct
14 Correct 8 ms 3288 KB Output is correct
15 Correct 9 ms 3132 KB Output is correct
16 Correct 8 ms 3284 KB Output is correct
17 Correct 7 ms 3544 KB Output is correct
18 Correct 5 ms 1168 KB Output is correct
19 Correct 408 ms 29600 KB Output is correct
20 Correct 406 ms 27444 KB Output is correct
21 Correct 424 ms 29616 KB Output is correct
22 Correct 315 ms 30124 KB Output is correct
23 Correct 308 ms 30640 KB Output is correct
24 Correct 213 ms 22456 KB Output is correct
25 Correct 389 ms 26680 KB Output is correct
26 Correct 396 ms 28200 KB Output is correct
27 Correct 387 ms 27568 KB Output is correct
28 Correct 280 ms 27768 KB Output is correct
29 Correct 260 ms 29360 KB Output is correct
30 Correct 198 ms 21172 KB Output is correct
31 Correct 489 ms 32176 KB Output is correct
32 Correct 464 ms 33456 KB Output is correct
33 Correct 414 ms 27380 KB Output is correct
34 Correct 379 ms 28832 KB Output is correct
35 Correct 361 ms 30260 KB Output is correct
36 Correct 213 ms 21688 KB Output is correct
37 Correct 466 ms 31944 KB Output is correct
38 Correct 477 ms 32488 KB Output is correct
39 Correct 476 ms 32288 KB Output is correct
40 Correct 304 ms 29612 KB Output is correct
41 Correct 266 ms 26352 KB Output is correct
42 Correct 199 ms 22708 KB Output is correct
43 Correct 579 ms 36764 KB Output is correct
44 Correct 532 ms 37272 KB Output is correct
45 Correct 549 ms 37296 KB Output is correct
46 Correct 453 ms 36012 KB Output is correct
47 Correct 402 ms 36432 KB Output is correct
48 Correct 223 ms 23224 KB Output is correct
49 Correct 521 ms 35504 KB Output is correct
50 Correct 525 ms 37276 KB Output is correct
51 Correct 493 ms 37356 KB Output is correct
52 Correct 378 ms 37380 KB Output is correct
53 Correct 284 ms 30012 KB Output is correct