Submission #944107

# Submission time Handle Problem Language Result Execution time Memory
944107 2024-03-12T08:33:23 Z yeediot Bitaro, who Leaps through Time (JOI19_timeleap) C++17
100 / 100
672 ms 96340 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];
int v[2][mxn];
node merge(node a,node b){
    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,r+i,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,r+p,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){
                cout<<merge(merge(node(0,b-a,b-a,0),query(0,1,n-1,1,a,c-1)),node(0,d-c,d-c,0)).k<<'\n';
            }
            else{
                cout<<merge(merge(node(0,b+a-1,b+a-1,0),query(1,1,n-1,1,c,a-1)),node(0,d+c-1,d+c-1,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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 75780 KB Output is correct
2 Correct 12 ms 75868 KB Output is correct
3 Correct 13 ms 75864 KB Output is correct
4 Correct 12 ms 75868 KB Output is correct
5 Correct 14 ms 75868 KB Output is correct
6 Correct 14 ms 75864 KB Output is correct
7 Correct 12 ms 75868 KB Output is correct
8 Correct 12 ms 75788 KB Output is correct
9 Correct 12 ms 75812 KB Output is correct
10 Correct 14 ms 75868 KB Output is correct
11 Correct 13 ms 76072 KB Output is correct
12 Correct 15 ms 75860 KB Output is correct
13 Correct 14 ms 75864 KB Output is correct
14 Correct 13 ms 75820 KB Output is correct
15 Correct 15 ms 75868 KB Output is correct
16 Correct 15 ms 75864 KB Output is correct
17 Correct 15 ms 75868 KB Output is correct
18 Correct 15 ms 75864 KB Output is correct
19 Correct 16 ms 75940 KB Output is correct
20 Correct 15 ms 76040 KB Output is correct
21 Correct 17 ms 76040 KB Output is correct
22 Correct 16 ms 75956 KB Output is correct
23 Correct 17 ms 75848 KB Output is correct
24 Correct 13 ms 76072 KB Output is correct
25 Correct 13 ms 75868 KB Output is correct
26 Correct 13 ms 75864 KB Output is correct
27 Correct 15 ms 75828 KB Output is correct
28 Correct 12 ms 75868 KB Output is correct
29 Correct 12 ms 75868 KB Output is correct
30 Correct 12 ms 75864 KB Output is correct
31 Correct 14 ms 75868 KB Output is correct
32 Correct 15 ms 75868 KB Output is correct
33 Correct 12 ms 75868 KB Output is correct
34 Correct 12 ms 75836 KB Output is correct
35 Correct 13 ms 75864 KB Output is correct
36 Correct 13 ms 75864 KB Output is correct
37 Correct 13 ms 75864 KB Output is correct
38 Correct 13 ms 76052 KB Output is correct
39 Correct 13 ms 75868 KB Output is correct
40 Correct 13 ms 75864 KB Output is correct
41 Correct 13 ms 75804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 80008 KB Output is correct
2 Correct 501 ms 95424 KB Output is correct
3 Correct 519 ms 95412 KB Output is correct
4 Correct 521 ms 95200 KB Output is correct
5 Correct 582 ms 95708 KB Output is correct
6 Correct 517 ms 95600 KB Output is correct
7 Correct 518 ms 95568 KB Output is correct
8 Correct 534 ms 96336 KB Output is correct
9 Correct 507 ms 95576 KB Output is correct
10 Correct 551 ms 95660 KB Output is correct
11 Correct 522 ms 95780 KB Output is correct
12 Correct 586 ms 96192 KB Output is correct
13 Correct 565 ms 96340 KB Output is correct
14 Correct 19 ms 75864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 75780 KB Output is correct
2 Correct 12 ms 75868 KB Output is correct
3 Correct 13 ms 75864 KB Output is correct
4 Correct 12 ms 75868 KB Output is correct
5 Correct 14 ms 75868 KB Output is correct
6 Correct 14 ms 75864 KB Output is correct
7 Correct 12 ms 75868 KB Output is correct
8 Correct 12 ms 75788 KB Output is correct
9 Correct 12 ms 75812 KB Output is correct
10 Correct 14 ms 75868 KB Output is correct
11 Correct 13 ms 76072 KB Output is correct
12 Correct 15 ms 75860 KB Output is correct
13 Correct 14 ms 75864 KB Output is correct
14 Correct 13 ms 75820 KB Output is correct
15 Correct 15 ms 75868 KB Output is correct
16 Correct 15 ms 75864 KB Output is correct
17 Correct 15 ms 75868 KB Output is correct
18 Correct 15 ms 75864 KB Output is correct
19 Correct 16 ms 75940 KB Output is correct
20 Correct 15 ms 76040 KB Output is correct
21 Correct 17 ms 76040 KB Output is correct
22 Correct 16 ms 75956 KB Output is correct
23 Correct 17 ms 75848 KB Output is correct
24 Correct 13 ms 76072 KB Output is correct
25 Correct 13 ms 75868 KB Output is correct
26 Correct 13 ms 75864 KB Output is correct
27 Correct 15 ms 75828 KB Output is correct
28 Correct 12 ms 75868 KB Output is correct
29 Correct 12 ms 75868 KB Output is correct
30 Correct 12 ms 75864 KB Output is correct
31 Correct 14 ms 75868 KB Output is correct
32 Correct 15 ms 75868 KB Output is correct
33 Correct 12 ms 75868 KB Output is correct
34 Correct 12 ms 75836 KB Output is correct
35 Correct 13 ms 75864 KB Output is correct
36 Correct 13 ms 75864 KB Output is correct
37 Correct 13 ms 75864 KB Output is correct
38 Correct 13 ms 76052 KB Output is correct
39 Correct 13 ms 75868 KB Output is correct
40 Correct 13 ms 75864 KB Output is correct
41 Correct 13 ms 75804 KB Output is correct
42 Correct 552 ms 80008 KB Output is correct
43 Correct 501 ms 95424 KB Output is correct
44 Correct 519 ms 95412 KB Output is correct
45 Correct 521 ms 95200 KB Output is correct
46 Correct 582 ms 95708 KB Output is correct
47 Correct 517 ms 95600 KB Output is correct
48 Correct 518 ms 95568 KB Output is correct
49 Correct 534 ms 96336 KB Output is correct
50 Correct 507 ms 95576 KB Output is correct
51 Correct 551 ms 95660 KB Output is correct
52 Correct 522 ms 95780 KB Output is correct
53 Correct 586 ms 96192 KB Output is correct
54 Correct 565 ms 96340 KB Output is correct
55 Correct 19 ms 75864 KB Output is correct
56 Correct 554 ms 92416 KB Output is correct
57 Correct 537 ms 92184 KB Output is correct
58 Correct 611 ms 92764 KB Output is correct
59 Correct 571 ms 92648 KB Output is correct
60 Correct 555 ms 92384 KB Output is correct
61 Correct 570 ms 92920 KB Output is correct
62 Correct 592 ms 92876 KB Output is correct
63 Correct 589 ms 92944 KB Output is correct
64 Correct 598 ms 93056 KB Output is correct
65 Correct 567 ms 92668 KB Output is correct
66 Correct 595 ms 92496 KB Output is correct
67 Correct 598 ms 92880 KB Output is correct
68 Correct 672 ms 91992 KB Output is correct
69 Correct 633 ms 93044 KB Output is correct
70 Correct 580 ms 92412 KB Output is correct
71 Correct 524 ms 91484 KB Output is correct
72 Correct 548 ms 91732 KB Output is correct
73 Correct 599 ms 92596 KB Output is correct
74 Correct 603 ms 92496 KB Output is correct
75 Correct 614 ms 92884 KB Output is correct
76 Correct 620 ms 93008 KB Output is correct
77 Correct 12 ms 75872 KB Output is correct