답안 #944230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944230 2024-03-12T12:03:21 Z yeediot Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
624 ms 92076 KB
#include<bits/stdc++.h>
#include <ostream>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
struct line{
    int a,b;
    int operator()(const int x)const{
        return a*x+b;
    }
};
bool check(line l1,line l2,line l3){
    return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a);
}
struct node{
    int ty,l,r,k;
    node(int ty=0,int l=0,int r=0,int k=0):ty(ty),l(l),r(r),k(k){}
};
const int mxn=3e5+5;
node seg[2][4*mxn];
node merge(node a,node b){
    //ty=0 代表該道路可在l~r之間使用,ty=1代表該區間起點在l,終點在r。
    node res=node();
    if(a.ty==0 and b.ty==0){
        if(max(a.l,b.l)<=min(a.r,b.r)){
            res=node(0,max(a.l,b.l),min(a.r,b.r),0);
        }
        else if(a.r<b.r){
            res=node(1,a.r,b.l,0);
        }
        else{
            res=node(1,a.l,b.r,max(0LL,a.l-b.r));
        }
    }
    else if(a.ty==0){
        res=node(1,max(a.l,min(a.r,b.l)),b.r,max(0LL,a.l-b.l));
    }
    else if(b.ty==0){
        res=node(1,a.l,max(b.l,min(a.r,b.r)),max(a.r-b.r,0LL));
    }
    else{
        res=node(1,a.l,b.r,max(0LL,a.r-b.l));
    }
    res.k+=a.k+b.k;
    return res;
}
void modify(bool f,int l,int r,int id,int p,node v){
    if(l==r){
        seg[f][id]=v;
        return ;
    }
    int mm=l+r>>1;
    if(p<=mm){
        modify(f,l,mm,id*2,p,v);
    }
    else{
        modify(f,mm+1,r,id*2+1,p,v);
    }
    if(!f)seg[f][id]=merge(seg[f][id*2],seg[f][id*2+1]);
    else seg[f][id]=merge(seg[f][id*2+1],seg[f][id*2]);
}
node query(bool f,int l,int r,int id,int ql,int qr){
    if(ql<=l and r<=qr){
        return seg[f][id];
    }
    int mm=l+r>>1;
    if(qr<=mm){
        return query(f,l,mm,id*2,ql,qr);
    }
    else if(ql>mm){
        return query(f,mm+1,r,id*2+1,ql,qr);
    }
    else{
        if(!f)return merge(query(f,l,mm,id*2,ql,mm),query(f,mm+1,r,id*2+1,mm+1,qr));
        else return merge(query(f,mm+1,r,id*2+1,mm+1,qr),query(f,l,mm,id*2,ql,mm));
    }
}
void operator<<(ostream&os,node a){
    cout<<a.ty<<','<<a.l<<','<<a.r<<','<<a.k<<' ';
}
signed main(){
    setio();
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;i++){
        int l,r;
        cin>>l>>r;
        r--;
        node x=node(0,l-i,r-i,0);
        modify(0,1,n-1,1,i,x);
        x=node(0,l+i+1,r+i+1,0);
        modify(1,1,n-1,1,i,x);
    }
    while(q--){
        int t;
        cin>>t;
        if(t==1){
            int p,l,r;
            cin>>p>>l>>r;
            r--;
            node x=node(0,l-p,r-p,0);
            modify(0,1,n-1,1,p,x);
            x=node(0,l+p+1,r+p+1,0);
            modify(1,1,n-1,1,p,x);
        }
        else{
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            if(a==c){
                cout<<max(b-d,0LL)<<'\n';
                continue;
            }
            if(a<c){
                b-=a;
                d-=c;
                cout<<merge(merge(node(0,b,b,0),query(0,1,n-1,1,a,c-1)),node(0,d,d,0)).k<<'\n';
            }
            else{
                b+=a;
                d+=c;
                cout<<merge(merge(node(0,b,b,0),query(1,1,n-1,1,c,a-1)),node(0,d,d,0)).k<<'\n';
                //a--;
                //b+=a;
                //d+=c-1;
            }
        }
    }
}
 /*
 input:
 [  {  ]  }
 {  [  }  ]
 [  ]  {  }
 {  }  [  ]
 [  {  }  ]
 {  [  ]  }
 */















 

Compilation message

timeleap.cpp: In function 'void modify(bool, long long int, long long int, long long int, long long int, node)':
timeleap.cpp:92:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |     int mm=l+r>>1;
      |            ~^~
timeleap.cpp: In function 'node query(bool, long long int, long long int, long long int, long long int, long long int)':
timeleap.cpp:106:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |     int mm=l+r>>1;
      |            ~^~
timeleap.cpp: In function 'void setIO(std::string)':
timeleap.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 75432 KB Output is correct
2 Correct 14 ms 75472 KB Output is correct
3 Correct 12 ms 75600 KB Output is correct
4 Correct 13 ms 75608 KB Output is correct
5 Correct 12 ms 75352 KB Output is correct
6 Correct 12 ms 75356 KB Output is correct
7 Correct 12 ms 75352 KB Output is correct
8 Correct 11 ms 75356 KB Output is correct
9 Correct 11 ms 75612 KB Output is correct
10 Correct 11 ms 75356 KB Output is correct
11 Correct 12 ms 75612 KB Output is correct
12 Correct 12 ms 75608 KB Output is correct
13 Correct 12 ms 75612 KB Output is correct
14 Correct 12 ms 75652 KB Output is correct
15 Correct 13 ms 75608 KB Output is correct
16 Correct 12 ms 75608 KB Output is correct
17 Correct 12 ms 75608 KB Output is correct
18 Correct 13 ms 75612 KB Output is correct
19 Correct 12 ms 75612 KB Output is correct
20 Correct 12 ms 75624 KB Output is correct
21 Correct 12 ms 75612 KB Output is correct
22 Correct 12 ms 75492 KB Output is correct
23 Correct 12 ms 75608 KB Output is correct
24 Correct 12 ms 75608 KB Output is correct
25 Correct 12 ms 75612 KB Output is correct
26 Correct 12 ms 75612 KB Output is correct
27 Correct 12 ms 75612 KB Output is correct
28 Correct 12 ms 75612 KB Output is correct
29 Correct 13 ms 75612 KB Output is correct
30 Correct 12 ms 75504 KB Output is correct
31 Correct 13 ms 75612 KB Output is correct
32 Correct 13 ms 75496 KB Output is correct
33 Correct 12 ms 75656 KB Output is correct
34 Correct 14 ms 75428 KB Output is correct
35 Correct 13 ms 75612 KB Output is correct
36 Correct 12 ms 75612 KB Output is correct
37 Correct 12 ms 75612 KB Output is correct
38 Correct 13 ms 75612 KB Output is correct
39 Correct 12 ms 75612 KB Output is correct
40 Correct 13 ms 75612 KB Output is correct
41 Correct 11 ms 75604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 519 ms 79696 KB Output is correct
2 Correct 499 ms 91452 KB Output is correct
3 Correct 502 ms 91472 KB Output is correct
4 Correct 505 ms 91732 KB Output is correct
5 Correct 515 ms 91780 KB Output is correct
6 Correct 506 ms 91616 KB Output is correct
7 Correct 521 ms 91948 KB Output is correct
8 Correct 549 ms 92076 KB Output is correct
9 Correct 497 ms 91792 KB Output is correct
10 Correct 514 ms 91736 KB Output is correct
11 Correct 518 ms 91696 KB Output is correct
12 Correct 539 ms 91956 KB Output is correct
13 Correct 548 ms 92068 KB Output is correct
14 Correct 11 ms 75356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 75432 KB Output is correct
2 Correct 14 ms 75472 KB Output is correct
3 Correct 12 ms 75600 KB Output is correct
4 Correct 13 ms 75608 KB Output is correct
5 Correct 12 ms 75352 KB Output is correct
6 Correct 12 ms 75356 KB Output is correct
7 Correct 12 ms 75352 KB Output is correct
8 Correct 11 ms 75356 KB Output is correct
9 Correct 11 ms 75612 KB Output is correct
10 Correct 11 ms 75356 KB Output is correct
11 Correct 12 ms 75612 KB Output is correct
12 Correct 12 ms 75608 KB Output is correct
13 Correct 12 ms 75612 KB Output is correct
14 Correct 12 ms 75652 KB Output is correct
15 Correct 13 ms 75608 KB Output is correct
16 Correct 12 ms 75608 KB Output is correct
17 Correct 12 ms 75608 KB Output is correct
18 Correct 13 ms 75612 KB Output is correct
19 Correct 12 ms 75612 KB Output is correct
20 Correct 12 ms 75624 KB Output is correct
21 Correct 12 ms 75612 KB Output is correct
22 Correct 12 ms 75492 KB Output is correct
23 Correct 12 ms 75608 KB Output is correct
24 Correct 12 ms 75608 KB Output is correct
25 Correct 12 ms 75612 KB Output is correct
26 Correct 12 ms 75612 KB Output is correct
27 Correct 12 ms 75612 KB Output is correct
28 Correct 12 ms 75612 KB Output is correct
29 Correct 13 ms 75612 KB Output is correct
30 Correct 12 ms 75504 KB Output is correct
31 Correct 13 ms 75612 KB Output is correct
32 Correct 13 ms 75496 KB Output is correct
33 Correct 12 ms 75656 KB Output is correct
34 Correct 14 ms 75428 KB Output is correct
35 Correct 13 ms 75612 KB Output is correct
36 Correct 12 ms 75612 KB Output is correct
37 Correct 12 ms 75612 KB Output is correct
38 Correct 13 ms 75612 KB Output is correct
39 Correct 12 ms 75612 KB Output is correct
40 Correct 13 ms 75612 KB Output is correct
41 Correct 11 ms 75604 KB Output is correct
42 Correct 519 ms 79696 KB Output is correct
43 Correct 499 ms 91452 KB Output is correct
44 Correct 502 ms 91472 KB Output is correct
45 Correct 505 ms 91732 KB Output is correct
46 Correct 515 ms 91780 KB Output is correct
47 Correct 506 ms 91616 KB Output is correct
48 Correct 521 ms 91948 KB Output is correct
49 Correct 549 ms 92076 KB Output is correct
50 Correct 497 ms 91792 KB Output is correct
51 Correct 514 ms 91736 KB Output is correct
52 Correct 518 ms 91696 KB Output is correct
53 Correct 539 ms 91956 KB Output is correct
54 Correct 548 ms 92068 KB Output is correct
55 Correct 11 ms 75356 KB Output is correct
56 Correct 563 ms 89048 KB Output is correct
57 Correct 514 ms 88620 KB Output is correct
58 Correct 553 ms 89172 KB Output is correct
59 Correct 622 ms 89032 KB Output is correct
60 Correct 554 ms 88824 KB Output is correct
61 Correct 561 ms 89168 KB Output is correct
62 Correct 550 ms 89168 KB Output is correct
63 Correct 559 ms 89316 KB Output is correct
64 Correct 583 ms 89052 KB Output is correct
65 Correct 552 ms 88860 KB Output is correct
66 Correct 550 ms 85020 KB Output is correct
67 Correct 559 ms 85304 KB Output is correct
68 Correct 527 ms 84936 KB Output is correct
69 Correct 624 ms 85480 KB Output is correct
70 Correct 534 ms 85088 KB Output is correct
71 Correct 548 ms 84564 KB Output is correct
72 Correct 543 ms 84944 KB Output is correct
73 Correct 587 ms 85148 KB Output is correct
74 Correct 576 ms 84948 KB Output is correct
75 Correct 567 ms 85004 KB Output is correct
76 Correct 581 ms 85388 KB Output is correct
77 Correct 12 ms 75612 KB Output is correct