답안 #119770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119770 2019-06-22T09:04:00 Z errorgorn Bitaro, who Leaps through Time (JOI19_timeleap) C++14
100 / 100
1480 ms 269684 KB
#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int,int> ii;
int n;
ii input[300005];
inline int read() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9'){
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
    return x;
}
struct stats{
    int l_time,r_time;
    long long time_used;
    long long powers_used;
    stats(int a,int b,int c, int d){
        l_time=a;
        r_time=b;
        time_used=c;
        powers_used=d;
    }
    stats(stats *i, stats *j){
        unions(i,j);
    }
    stats(stats *i){
        l_time=i->l_time;
        r_time=i->r_time;
        time_used=i->time_used;
        powers_used=i->powers_used;
    }
    void unions(stats *l,stats *r){
        powers_used=l->powers_used+r->powers_used;
        time_used=l->time_used+r->time_used;
        int left=l->l_time+l->time_used,right=l->r_time+l->time_used;
        if (max(left,r->l_time)<=min(right,r->r_time)){
            l_time=max(left,r->l_time)-l->time_used;
            r_time=min(right,r->r_time)-l->time_used;
        }
        else if (right<r->l_time){
            time_used+=r->l_time-right;
            l_time=l->r_time;
            r_time=l_time;
        }
        else{
            powers_used+=left-r->r_time;
            time_used-=left-r->r_time;
            l_time=l->l_time;
            r_time=l_time;
        }
    }
};
struct node{
    int s,e,m;
    stats *val;
    node *l,*r;
    node (int _s,int _e){
        s=_s,e=_e,m=(s+e)>>1;
        if (s==e){
            val=new stats(input[s].first,input[s].second-1,1,0);
        }
        else{
            l=new node(s,m);
            r=new node(m+1,e);
            val=new stats(l->val,r->val);
        }
    }
    stats* query(int i,int j){
        if (s==i && e==j) return val;
        else if (j<=m) return l->query(i,j);
        else if (m<i) return r->query(i,j);
        else return new stats(l->query(i,m),r->query(m+1,j));
    }
    void update(int i){
        if (s==e){
            val=new stats(input[s].first,input[s].second-1,1,0);
        }
        else{
            if (i<=m) l->update(i);
            else r->update(i);
            val->unions(l->val,r->val);
        }
    }
}*root;
struct rnode{
    int s,e,m;
    stats *val;
    rnode *l,*r;
    rnode (int _s,int _e){
        s=_s,e=_e,m=(s+e)>>1;
        if (s==e){
            val=new stats(input[n-s].first,input[n-s].second-1,1,0);
        }
        else{
            l=new rnode(s,m);
            r=new rnode(m+1,e);
            val=new stats(l->val,r->val);
        }
    }
    stats* query(int i,int j){
        if (s==i && e==j) return val;
        else if (j<=m) return l->query(i,j);
        else if (m<i) return r->query(i,j);
        else return new stats(l->query(i,m),r->query(m+1,j));
    }
    void update(int i){
        if (s==e){
            val=new stats(input[n-s].first,input[n-s].second-1,1,0);
        }
        else{
            if (i<=m) l->update(i);
            else r->update(i);
            val->unions(l->val,r->val);
        }
    }
}*rroot;
int main(){
    //freopen("input.txt","r",stdin);
    int q;
    n=read();
    q=read();
    if (n==1){
        int a,b;
        while (q--){
            read(),read();
            a=read();
            read();
            b=read();
            if (a>b) printf("%d\n",a-b);
            else printf("0\n");
        }
        return 0;
    }
    for (int x=1;x<n;x++) input[x].first=read(),input[x].second=read();
    root=new node(1,n-1);
    rroot=new rnode(1,n-1);
    int a,b,c,d;
    int type;
    stats *res;
    int fin_time;
    while (q--){
        type=read();
        if (type==2){
            a=read();
            b=read();
            c=read();
            d=read();
            if (a<c) res=new stats(root->query(a,c-1));
            else if (c<a) res=new stats(rroot->query(n-a+1,n-c));
            else{
                if (b>d) printf("%d\n",b-d);
                else printf("0\n");
                continue;
            }
            //printf("%lld %lld %lld %lld\n",res->l_time,res->r_time,res->time_used,res->powers_used);
            fin_time=max(b,res->l_time);
            if (b>res->r_time){
                res->powers_used+=b-res->r_time;
                fin_time=res->r_time;
            }
            fin_time+=res->time_used;
            if (d<fin_time){
                res->powers_used+=fin_time-d;
            }
            printf("%lld\n",res->powers_used);
        }
        else{
            a=read();
            b=read();
            c=read();
            input[a]=ii(b,c);
            root->update(a);
            rroot->update(n-a);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 0 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 3 ms 768 KB Output is correct
22 Correct 3 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 3 ms 896 KB Output is correct
35 Correct 3 ms 768 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 3 ms 768 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 3 ms 768 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1320 ms 256596 KB Output is correct
2 Correct 1300 ms 252876 KB Output is correct
3 Correct 1262 ms 253948 KB Output is correct
4 Correct 1210 ms 250744 KB Output is correct
5 Correct 1260 ms 259192 KB Output is correct
6 Correct 1278 ms 256864 KB Output is correct
7 Correct 1309 ms 260632 KB Output is correct
8 Correct 1273 ms 265892 KB Output is correct
9 Correct 1241 ms 251724 KB Output is correct
10 Correct 1279 ms 260376 KB Output is correct
11 Correct 1455 ms 259064 KB Output is correct
12 Correct 1324 ms 267860 KB Output is correct
13 Correct 1317 ms 269684 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 0 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 4 ms 768 KB Output is correct
21 Correct 3 ms 768 KB Output is correct
22 Correct 3 ms 768 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 4 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 3 ms 896 KB Output is correct
35 Correct 3 ms 768 KB Output is correct
36 Correct 3 ms 768 KB Output is correct
37 Correct 3 ms 768 KB Output is correct
38 Correct 3 ms 768 KB Output is correct
39 Correct 3 ms 768 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Correct 1320 ms 256596 KB Output is correct
43 Correct 1300 ms 252876 KB Output is correct
44 Correct 1262 ms 253948 KB Output is correct
45 Correct 1210 ms 250744 KB Output is correct
46 Correct 1260 ms 259192 KB Output is correct
47 Correct 1278 ms 256864 KB Output is correct
48 Correct 1309 ms 260632 KB Output is correct
49 Correct 1273 ms 265892 KB Output is correct
50 Correct 1241 ms 251724 KB Output is correct
51 Correct 1279 ms 260376 KB Output is correct
52 Correct 1455 ms 259064 KB Output is correct
53 Correct 1324 ms 267860 KB Output is correct
54 Correct 1317 ms 269684 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 1193 ms 188636 KB Output is correct
57 Correct 1194 ms 181932 KB Output is correct
58 Correct 1247 ms 191596 KB Output is correct
59 Correct 1242 ms 192904 KB Output is correct
60 Correct 1166 ms 184688 KB Output is correct
61 Correct 1263 ms 196296 KB Output is correct
62 Correct 1307 ms 195628 KB Output is correct
63 Correct 1186 ms 195080 KB Output is correct
64 Correct 1272 ms 196132 KB Output is correct
65 Correct 1183 ms 190328 KB Output is correct
66 Correct 1162 ms 191128 KB Output is correct
67 Correct 1209 ms 195448 KB Output is correct
68 Correct 1200 ms 185976 KB Output is correct
69 Correct 1221 ms 199100 KB Output is correct
70 Correct 1137 ms 185336 KB Output is correct
71 Correct 1126 ms 181112 KB Output is correct
72 Correct 1161 ms 185480 KB Output is correct
73 Correct 1306 ms 196496 KB Output is correct
74 Correct 1277 ms 197008 KB Output is correct
75 Correct 1480 ms 199068 KB Output is correct
76 Correct 1238 ms 199688 KB Output is correct
77 Correct 2 ms 256 KB Output is correct