답안 #126762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126762 2019-07-08T11:09:00 Z TadijaSebez Bitaro, who Leaps through Time (JOI19_timeleap) C++11
100 / 100
1420 ms 67780 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300050;
const int M=4*N;
const ll inf=1e18;
struct Node
{
	ll l,r,cost,go;
	Node():l(-inf),r(inf),cost(0),go(inf){}
	Node(ll _l, ll _r, ll _cost, ll _go):l(_l),r(_r),cost(_cost),go(_go){}
};
Node operator + (Node a, Node b)
{
	Node ans;
	if(a.go!=inf) ans=Node(a.l,a.r,a.cost+max(a.go-b.r,(ll)0),max(min(a.go,b.r),b.l));
	else if(a.r<b.l) ans=Node(a.r,a.r,0,b.l);
	else if(a.l>b.r) ans=Node(a.l,a.l,a.l-b.r,b.r);
	else if(b.go!=inf) return b;
	else ans=Node(max(a.l,b.l),min(a.r,b.r),0,inf);
	if(b.go!=inf) ans.go=b.go,ans.cost+=b.cost;
	return ans;
}
int ls[M],rs[M],root[2],tsz,n;
Node node[M];
void Set(int &c, int ss, int se, int qi, int l, int r)
{
	if(!c) c=++tsz;
	if(ss==se){ node[c]=Node(l-qi,r-qi-1,0,inf);return;}
	int mid=ss+se>>1;
	if(qi<=mid) Set(ls[c],ss,mid,qi,l,r);
	else Set(rs[c],mid+1,se,qi,l,r);
	node[c]=node[ls[c]]+node[rs[c]];
}
Node Get(int c, int ss, int se, int qs, int qe)
{
	if(qs>qe || qs>se || ss>qe) return Node();
	if(qs<=ss && qe>=se) return node[c];
	int mid=ss+se>>1;
	return Get(ls[c],ss,mid,qs,qe)+Get(rs[c],mid+1,se,qs,qe);
}
void Upd(int x, int l, int r)
{
	Set(root[0],1,n-1,x,l,r);
	Set(root[1],1,n-1,n-x,l,r);
}
int main()
{
	int q,t,x,y,l,r;
	scanf("%i %i",&n,&q);
	for(int i=1;i<n;i++) scanf("%i %i",&l,&r),Upd(i,l,r);
	while(q--)
	{
		scanf("%i",&t);
		if(t==1) scanf("%i %i %i",&x,&l,&r),Upd(x,l,r);
		else
		{
			scanf("%i %i %i %i",&x,&l,&y,&r);
			if(x==y) printf("%i\n",max(l-r,0));
			else
			{
				int rt=0;
				if(x>y) rt=1,x=n-x+1,y=n-y+1;
				Node ans=Node(l-x,l-x,0,inf)+Get(root[rt],1,n-1,x,y-1)+Node(r-y,r-y,0,inf);
				printf("%lld\n",ans.cost);
			}
		}
	}
	return 0;
}

Compilation message

timeleap.cpp: In function 'void Set(int&, int, int, int, int, int)':
timeleap.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
timeleap.cpp: In function 'Node Get(int, int, int, int, int)':
timeleap.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
timeleap.cpp: In function 'int main()':
timeleap.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
timeleap.cpp:51:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<n;i++) scanf("%i %i",&l,&r),Upd(i,l,r);
                       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
timeleap.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i",&t);
   ~~~~~^~~~~~~~~
timeleap.cpp:55:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   if(t==1) scanf("%i %i %i",&x,&l,&r),Upd(x,l,r);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
timeleap.cpp:58:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%i %i %i %i",&x,&l,&y,&r);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 38008 KB Output is correct
2 Correct 32 ms 37880 KB Output is correct
3 Correct 33 ms 37880 KB Output is correct
4 Correct 33 ms 37884 KB Output is correct
5 Correct 33 ms 37852 KB Output is correct
6 Correct 32 ms 37880 KB Output is correct
7 Correct 32 ms 37880 KB Output is correct
8 Correct 32 ms 38008 KB Output is correct
9 Correct 32 ms 37880 KB Output is correct
10 Correct 32 ms 37880 KB Output is correct
11 Correct 34 ms 38136 KB Output is correct
12 Correct 34 ms 38008 KB Output is correct
13 Correct 41 ms 38008 KB Output is correct
14 Correct 34 ms 38136 KB Output is correct
15 Correct 34 ms 38008 KB Output is correct
16 Correct 34 ms 37948 KB Output is correct
17 Correct 36 ms 38008 KB Output is correct
18 Correct 34 ms 38008 KB Output is correct
19 Correct 34 ms 38008 KB Output is correct
20 Correct 42 ms 38008 KB Output is correct
21 Correct 35 ms 37952 KB Output is correct
22 Correct 34 ms 38008 KB Output is correct
23 Correct 34 ms 38008 KB Output is correct
24 Correct 34 ms 37980 KB Output is correct
25 Correct 34 ms 38008 KB Output is correct
26 Correct 35 ms 38008 KB Output is correct
27 Correct 34 ms 38008 KB Output is correct
28 Correct 34 ms 38008 KB Output is correct
29 Correct 35 ms 38008 KB Output is correct
30 Correct 35 ms 38008 KB Output is correct
31 Correct 34 ms 38008 KB Output is correct
32 Correct 34 ms 38008 KB Output is correct
33 Correct 35 ms 38008 KB Output is correct
34 Correct 34 ms 38008 KB Output is correct
35 Correct 35 ms 37980 KB Output is correct
36 Correct 35 ms 38008 KB Output is correct
37 Correct 34 ms 38008 KB Output is correct
38 Correct 34 ms 38008 KB Output is correct
39 Correct 34 ms 38008 KB Output is correct
40 Correct 34 ms 38008 KB Output is correct
41 Correct 32 ms 37880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1254 ms 66316 KB Output is correct
2 Correct 1234 ms 65480 KB Output is correct
3 Correct 1252 ms 65576 KB Output is correct
4 Correct 1239 ms 65176 KB Output is correct
5 Correct 1270 ms 66296 KB Output is correct
6 Correct 1291 ms 66124 KB Output is correct
7 Correct 1294 ms 66552 KB Output is correct
8 Correct 1349 ms 67320 KB Output is correct
9 Correct 1227 ms 65532 KB Output is correct
10 Correct 1257 ms 66552 KB Output is correct
11 Correct 1384 ms 66384 KB Output is correct
12 Correct 1306 ms 67512 KB Output is correct
13 Correct 1340 ms 67780 KB Output is correct
14 Correct 31 ms 37880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 38008 KB Output is correct
2 Correct 32 ms 37880 KB Output is correct
3 Correct 33 ms 37880 KB Output is correct
4 Correct 33 ms 37884 KB Output is correct
5 Correct 33 ms 37852 KB Output is correct
6 Correct 32 ms 37880 KB Output is correct
7 Correct 32 ms 37880 KB Output is correct
8 Correct 32 ms 38008 KB Output is correct
9 Correct 32 ms 37880 KB Output is correct
10 Correct 32 ms 37880 KB Output is correct
11 Correct 34 ms 38136 KB Output is correct
12 Correct 34 ms 38008 KB Output is correct
13 Correct 41 ms 38008 KB Output is correct
14 Correct 34 ms 38136 KB Output is correct
15 Correct 34 ms 38008 KB Output is correct
16 Correct 34 ms 37948 KB Output is correct
17 Correct 36 ms 38008 KB Output is correct
18 Correct 34 ms 38008 KB Output is correct
19 Correct 34 ms 38008 KB Output is correct
20 Correct 42 ms 38008 KB Output is correct
21 Correct 35 ms 37952 KB Output is correct
22 Correct 34 ms 38008 KB Output is correct
23 Correct 34 ms 38008 KB Output is correct
24 Correct 34 ms 37980 KB Output is correct
25 Correct 34 ms 38008 KB Output is correct
26 Correct 35 ms 38008 KB Output is correct
27 Correct 34 ms 38008 KB Output is correct
28 Correct 34 ms 38008 KB Output is correct
29 Correct 35 ms 38008 KB Output is correct
30 Correct 35 ms 38008 KB Output is correct
31 Correct 34 ms 38008 KB Output is correct
32 Correct 34 ms 38008 KB Output is correct
33 Correct 35 ms 38008 KB Output is correct
34 Correct 34 ms 38008 KB Output is correct
35 Correct 35 ms 37980 KB Output is correct
36 Correct 35 ms 38008 KB Output is correct
37 Correct 34 ms 38008 KB Output is correct
38 Correct 34 ms 38008 KB Output is correct
39 Correct 34 ms 38008 KB Output is correct
40 Correct 34 ms 38008 KB Output is correct
41 Correct 32 ms 37880 KB Output is correct
42 Correct 1254 ms 66316 KB Output is correct
43 Correct 1234 ms 65480 KB Output is correct
44 Correct 1252 ms 65576 KB Output is correct
45 Correct 1239 ms 65176 KB Output is correct
46 Correct 1270 ms 66296 KB Output is correct
47 Correct 1291 ms 66124 KB Output is correct
48 Correct 1294 ms 66552 KB Output is correct
49 Correct 1349 ms 67320 KB Output is correct
50 Correct 1227 ms 65532 KB Output is correct
51 Correct 1257 ms 66552 KB Output is correct
52 Correct 1384 ms 66384 KB Output is correct
53 Correct 1306 ms 67512 KB Output is correct
54 Correct 1340 ms 67780 KB Output is correct
55 Correct 31 ms 37880 KB Output is correct
56 Correct 1262 ms 63148 KB Output is correct
57 Correct 1256 ms 62172 KB Output is correct
58 Correct 1289 ms 63608 KB Output is correct
59 Correct 1262 ms 63700 KB Output is correct
60 Correct 1310 ms 62532 KB Output is correct
61 Correct 1308 ms 64092 KB Output is correct
62 Correct 1289 ms 64152 KB Output is correct
63 Correct 1324 ms 63964 KB Output is correct
64 Correct 1420 ms 64156 KB Output is correct
65 Correct 1301 ms 63248 KB Output is correct
66 Correct 1268 ms 63352 KB Output is correct
67 Correct 1301 ms 63892 KB Output is correct
68 Correct 1248 ms 62424 KB Output is correct
69 Correct 1322 ms 64504 KB Output is correct
70 Correct 1249 ms 62592 KB Output is correct
71 Correct 1243 ms 61520 KB Output is correct
72 Correct 1257 ms 62152 KB Output is correct
73 Correct 1323 ms 63636 KB Output is correct
74 Correct 1295 ms 63736 KB Output is correct
75 Correct 1289 ms 64060 KB Output is correct
76 Correct 1334 ms 64592 KB Output is correct
77 Correct 32 ms 37880 KB Output is correct