답안 #1079831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079831 2024-08-29T02:17:28 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
462 ms 49444 KB
// #pragma GCC optimize("O3","unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e5;
struct Node{
    int x,y,s,ty;
};
vector <Node> v;
int n,q,ans[N+5];
void Rs(int l, int r){
    int md=l+r>>1;
    int x=l,y=md+1;
    vector <Node> dq;
    while (x<=md || y<=r){
        if (x>md) dq.push_back(v[y++]);
        else if (y>r) dq.push_back(v[x++]);
        else if (v[x].y<v[y].y) dq.push_back(v[x++]);
        else dq.push_back(v[y++]);
    }
    for (int i=r;i>=l;--i){
        v[i]=dq.back();
        dq.pop_back();
    }
}
bool comp(Node a, Node b){
    if (a.x!=b.x) return a.x<b.x;
    if (a.y!=b.y) return a.y<b.y;
    if (a.s!=b.s) return a.s<b.s;
    return a.ty>b.ty;
}
struct Fenwick_Tree{
    int FT[N+5];
    void clear(){
        for (int i=1;i<=N;++i) FT[i]=0;
    }
    void Update(int idx, int val){
        for (;idx<=N;idx+=idx&(-idx)) FT[idx]+=val;
    }
    int Get(int idx){
        int val=0;
        for (;idx;idx-=idx&(-idx)) val+=FT[idx];
        return val;
    }
    int Sum(int l, int r){
        return Get(r)-Get(l-1);
    }
} fw;
void dnc(int l, int r){
    if (l>=r) return;
    int md=l+r>>1;
    dnc(l,md);
    dnc(md+1,r);
    int pointer=md+1;
    for (int i=md+1;i<=r;++i) 
        if (!v[i].ty) fw.Update(v[i].s,1);
    for (int i=l;i<=md;++i){
        while (pointer<=r && v[pointer].y<v[i].y){
            if (!v[pointer].ty) fw.Update(v[pointer].s,-1);
            ++pointer;
        }
        if (v[i].ty) ans[v[i].ty]+=fw.Sum(v[i].s,N);
    }
    for (int i=pointer;i<=r;++i)
        if (!v[i].ty) fw.Update(v[i].s,-1);
    Rs(l,r);
}
void Solve(){
    cin>>n>>q;
    v.push_back({0,0,0,0});
    for (int i=1;i<=n;++i){
        int x,y;
        cin>>x>>y;
        v.push_back({x,y,x+y,0});
    }
    for (int i=1;i<=q;++i){
        int x,y,z;
        cin>>x>>y>>z;
        v.push_back({x,y,z,i});
    }
    sort(v.begin()+1,v.end(),comp);
    map <int,int> mp,cnt;
    for (int i=1;i<=n+q;++i) mp[v[i].s]=1;
    int idx=0;
    for (pair <int,int> x : mp)
        cnt[x.first]=++idx;
    for (int i=1;i<=n+q;++i) v[i].s=cnt[v[i].s];
    // for (int i=1;i<=n+q;++i) cout<<v[i].x<<' '<<v[i].y<<' '<<v[i].s<<"\n";
    // cout<<"\n";
    dnc(1,n+q);
    for (int i=1;i<=q;++i) cout<<ans[i]<<"\n";
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen("file.inp","r")){
        freopen ("file.inp","r",stdin);
        freopen ("file.out","w",stdout);
    }
    int t=1;
    // cin>>t;
    while (t--) Solve();
    cerr<<"\nTIME: "<<1000*clock()/CLOCKS_PER_SEC <<"ms.";
}

Compilation message

examination.cpp: In function 'void Rs(long long int, long long int)':
examination.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |     int md=l+r>>1;
      |            ~^~
examination.cpp: In function 'void dnc(long long int, long long int)':
examination.cpp:52:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int md=l+r>>1;
      |            ~^~
examination.cpp: In function 'int main()':
examination.cpp:98:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen ("file.inp","r",stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:99:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen ("file.out","w",stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 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 9 ms 1824 KB Output is correct
8 Correct 8 ms 1820 KB Output is correct
9 Correct 8 ms 3872 KB Output is correct
10 Correct 7 ms 3816 KB Output is correct
11 Correct 7 ms 3872 KB Output is correct
12 Correct 4 ms 3100 KB Output is correct
13 Correct 6 ms 3424 KB Output is correct
14 Correct 7 ms 3360 KB Output is correct
15 Correct 6 ms 3360 KB Output is correct
16 Correct 5 ms 3424 KB Output is correct
17 Correct 7 ms 3872 KB Output is correct
18 Correct 4 ms 1052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 31884 KB Output is correct
2 Correct 305 ms 30068 KB Output is correct
3 Correct 274 ms 31196 KB Output is correct
4 Correct 210 ms 32568 KB Output is correct
5 Correct 203 ms 30096 KB Output is correct
6 Correct 167 ms 22264 KB Output is correct
7 Correct 253 ms 30868 KB Output is correct
8 Correct 255 ms 31276 KB Output is correct
9 Correct 244 ms 31544 KB Output is correct
10 Correct 185 ms 31744 KB Output is correct
11 Correct 187 ms 32792 KB Output is correct
12 Correct 155 ms 20728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 31884 KB Output is correct
2 Correct 305 ms 30068 KB Output is correct
3 Correct 274 ms 31196 KB Output is correct
4 Correct 210 ms 32568 KB Output is correct
5 Correct 203 ms 30096 KB Output is correct
6 Correct 167 ms 22264 KB Output is correct
7 Correct 253 ms 30868 KB Output is correct
8 Correct 255 ms 31276 KB Output is correct
9 Correct 244 ms 31544 KB Output is correct
10 Correct 185 ms 31744 KB Output is correct
11 Correct 187 ms 32792 KB Output is correct
12 Correct 155 ms 20728 KB Output is correct
13 Correct 353 ms 37540 KB Output is correct
14 Correct 340 ms 35868 KB Output is correct
15 Correct 268 ms 31544 KB Output is correct
16 Correct 276 ms 35764 KB Output is correct
17 Correct 314 ms 35120 KB Output is correct
18 Correct 163 ms 21388 KB Output is correct
19 Correct 365 ms 36684 KB Output is correct
20 Correct 351 ms 38284 KB Output is correct
21 Correct 347 ms 36760 KB Output is correct
22 Correct 209 ms 32356 KB Output is correct
23 Correct 189 ms 28436 KB Output is correct
24 Correct 156 ms 22940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 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 9 ms 1824 KB Output is correct
8 Correct 8 ms 1820 KB Output is correct
9 Correct 8 ms 3872 KB Output is correct
10 Correct 7 ms 3816 KB Output is correct
11 Correct 7 ms 3872 KB Output is correct
12 Correct 4 ms 3100 KB Output is correct
13 Correct 6 ms 3424 KB Output is correct
14 Correct 7 ms 3360 KB Output is correct
15 Correct 6 ms 3360 KB Output is correct
16 Correct 5 ms 3424 KB Output is correct
17 Correct 7 ms 3872 KB Output is correct
18 Correct 4 ms 1052 KB Output is correct
19 Correct 265 ms 31884 KB Output is correct
20 Correct 305 ms 30068 KB Output is correct
21 Correct 274 ms 31196 KB Output is correct
22 Correct 210 ms 32568 KB Output is correct
23 Correct 203 ms 30096 KB Output is correct
24 Correct 167 ms 22264 KB Output is correct
25 Correct 253 ms 30868 KB Output is correct
26 Correct 255 ms 31276 KB Output is correct
27 Correct 244 ms 31544 KB Output is correct
28 Correct 185 ms 31744 KB Output is correct
29 Correct 187 ms 32792 KB Output is correct
30 Correct 155 ms 20728 KB Output is correct
31 Correct 353 ms 37540 KB Output is correct
32 Correct 340 ms 35868 KB Output is correct
33 Correct 268 ms 31544 KB Output is correct
34 Correct 276 ms 35764 KB Output is correct
35 Correct 314 ms 35120 KB Output is correct
36 Correct 163 ms 21388 KB Output is correct
37 Correct 365 ms 36684 KB Output is correct
38 Correct 351 ms 38284 KB Output is correct
39 Correct 347 ms 36760 KB Output is correct
40 Correct 209 ms 32356 KB Output is correct
41 Correct 189 ms 28436 KB Output is correct
42 Correct 156 ms 22940 KB Output is correct
43 Correct 418 ms 48852 KB Output is correct
44 Correct 428 ms 48776 KB Output is correct
45 Correct 462 ms 46972 KB Output is correct
46 Correct 345 ms 47432 KB Output is correct
47 Correct 338 ms 48960 KB Output is correct
48 Correct 163 ms 23764 KB Output is correct
49 Correct 394 ms 49444 KB Output is correct
50 Correct 387 ms 48956 KB Output is correct
51 Correct 390 ms 47400 KB Output is correct
52 Correct 312 ms 47812 KB Output is correct
53 Correct 238 ms 34816 KB Output is correct