#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int L[300000],R[300000];
int T[300000],A[300000],B[300000],C[300000],D[300000];
int l[300000],r[300000];
LLI ans[300000];
struct func {
LLI a,b,c,p;
plli eval(LLI x) {
if (x > p) return mp(b,c+x-p);
else return mp(max(b+x-p,a),c);
}
};
func com(func a,func b) {
func c;
c.a = b.eval(a.a).first,c.b = b.eval(a.b).first;
c.c = a.c+b.eval(a.a).second;
c.p = min(a.p,a.p-a.b+max(b.p,a.a));
return c;
}
func tree[1 << 20];
int build(int s,int e,int i) {
if (s == e) {
tree[i] = (func){l[s],r[s],0,r[s]};
return 0;
}
int mid = (s+e) / 2;
build(s,mid,2*i+1),build(mid+1,e,2*i+2);
tree[i] = com(tree[2*i+1],tree[2*i+2]);
return 0;
}
int update(int s,int e,int ai,int i) {
if ((s > ai) || (e < ai)) return 0;
else if (s == e) {
tree[i] = (func){l[s],r[s],0,r[s]};
return 0;
}
int mid = (s+e) / 2;
update(s,mid,ai,2*i+1),update(mid+1,e,ai,2*i+2);
tree[i] = com(tree[2*i+1],tree[2*i+2]);
return 0;
}
func query(int s,int e,int qs,int qe,int i) {
if ((s > qe) || (e < qs)) return (func){(LLI) -1e12,(LLI) 1e12,0,(LLI) 1e12};
else if ((s >= qs) && (e <= qe)) return tree[i];
int mid = (s+e) / 2;
return com(query(s,mid,qs,qe,2*i+1),query(mid+1,e,qs,qe,2*i+2));
}
int main() {
int i;
int N,Q;
scanf("%d %d",&N,&Q);
for (i = 0; i < N-1; i++) scanf("%d %d",&L[i],&R[i]);
for (i = 0; i < Q; i++) {
scanf("%d",&T[i]);
if (T[i] == 1) scanf("%d %d %d",&A[i],&B[i],&C[i]),A[i]--,ans[i] = -1;
else {
scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]),A[i]--,C[i]--;
if (A[i] == C[i]) ans[i] = max(B[i]-D[i],0);
}
}
int rr;
for (rr = 0; rr < 2; rr++) {
if (N == 1) break;
for (i = 0; i < N-1; i++) l[i] = L[i]-i,r[i] = R[i]-i-1;
build(0,N-2,0);
for (i = 0; i < Q; i++) {
if (T[i] == 1) {
l[A[i]] = B[i]-A[i],r[A[i]] = C[i]-A[i]-1;
update(0,N-2,A[i],0);
}
else if ((T[i] == 2) && (A[i] < C[i])) {
func f = query(0,N-2,A[i],C[i]-1,0);
plli p = f.eval(B[i]-A[i]);
if (p.first > (D[i]-C[i])) p.second += p.first-(D[i]-C[i]);
ans[i] = p.second;
}
}
reverse(L,L+N-1),reverse(R,R+N-1);
for (i = 0; i < Q; i++) {
if (T[i] == 1) A[i] = N-2-A[i];
else if (T[i] == 2) A[i] = N-1-A[i],C[i] = N-1-C[i];
}
}
for (i = 0; i < Q; i++) {
if (ans[i] != -1) printf("%lld\n",ans[i]);
}
return 0;
}
Compilation message
timeleap.cpp: In function 'int main()':
timeleap.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&Q);
~~~~~^~~~~~~~~~~~~~~
timeleap.cpp:111:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < N-1; i++) scanf("%d %d",&L[i],&R[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
timeleap.cpp:113:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&T[i]);
~~~~~^~~~~~~~~~~~
timeleap.cpp:114:66: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
if (T[i] == 1) scanf("%d %d %d",&A[i],&B[i],&C[i]),A[i]--,ans[i] = -1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
timeleap.cpp:116:64: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d",&A[i],&B[i],&C[i],&D[i]),A[i]--,C[i]--;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
4 ms |
512 KB |
Output is correct |
20 |
Correct |
4 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
3 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
512 KB |
Output is correct |
33 |
Correct |
3 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
512 KB |
Output is correct |
35 |
Correct |
4 ms |
512 KB |
Output is correct |
36 |
Correct |
3 ms |
512 KB |
Output is correct |
37 |
Correct |
4 ms |
512 KB |
Output is correct |
38 |
Correct |
4 ms |
512 KB |
Output is correct |
39 |
Correct |
4 ms |
512 KB |
Output is correct |
40 |
Correct |
3 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
722 ms |
52244 KB |
Output is correct |
2 |
Correct |
700 ms |
35564 KB |
Output is correct |
3 |
Correct |
702 ms |
35448 KB |
Output is correct |
4 |
Correct |
668 ms |
35192 KB |
Output is correct |
5 |
Correct |
721 ms |
52088 KB |
Output is correct |
6 |
Correct |
700 ms |
51832 KB |
Output is correct |
7 |
Correct |
697 ms |
52060 KB |
Output is correct |
8 |
Correct |
760 ms |
52344 KB |
Output is correct |
9 |
Correct |
692 ms |
35448 KB |
Output is correct |
10 |
Correct |
968 ms |
52024 KB |
Output is correct |
11 |
Correct |
750 ms |
52064 KB |
Output is correct |
12 |
Correct |
803 ms |
52328 KB |
Output is correct |
13 |
Correct |
748 ms |
52472 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
4 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
4 ms |
512 KB |
Output is correct |
20 |
Correct |
4 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
4 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
3 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
512 KB |
Output is correct |
33 |
Correct |
3 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
512 KB |
Output is correct |
35 |
Correct |
4 ms |
512 KB |
Output is correct |
36 |
Correct |
3 ms |
512 KB |
Output is correct |
37 |
Correct |
4 ms |
512 KB |
Output is correct |
38 |
Correct |
4 ms |
512 KB |
Output is correct |
39 |
Correct |
4 ms |
512 KB |
Output is correct |
40 |
Correct |
3 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
42 |
Correct |
722 ms |
52244 KB |
Output is correct |
43 |
Correct |
700 ms |
35564 KB |
Output is correct |
44 |
Correct |
702 ms |
35448 KB |
Output is correct |
45 |
Correct |
668 ms |
35192 KB |
Output is correct |
46 |
Correct |
721 ms |
52088 KB |
Output is correct |
47 |
Correct |
700 ms |
51832 KB |
Output is correct |
48 |
Correct |
697 ms |
52060 KB |
Output is correct |
49 |
Correct |
760 ms |
52344 KB |
Output is correct |
50 |
Correct |
692 ms |
35448 KB |
Output is correct |
51 |
Correct |
968 ms |
52024 KB |
Output is correct |
52 |
Correct |
750 ms |
52064 KB |
Output is correct |
53 |
Correct |
803 ms |
52328 KB |
Output is correct |
54 |
Correct |
748 ms |
52472 KB |
Output is correct |
55 |
Correct |
2 ms |
384 KB |
Output is correct |
56 |
Correct |
846 ms |
62332 KB |
Output is correct |
57 |
Correct |
765 ms |
45248 KB |
Output is correct |
58 |
Correct |
810 ms |
62584 KB |
Output is correct |
59 |
Correct |
795 ms |
62712 KB |
Output is correct |
60 |
Correct |
772 ms |
45504 KB |
Output is correct |
61 |
Correct |
863 ms |
62956 KB |
Output is correct |
62 |
Correct |
853 ms |
62948 KB |
Output is correct |
63 |
Correct |
865 ms |
62840 KB |
Output is correct |
64 |
Correct |
870 ms |
62972 KB |
Output is correct |
65 |
Correct |
790 ms |
62328 KB |
Output is correct |
66 |
Correct |
809 ms |
62456 KB |
Output is correct |
67 |
Correct |
799 ms |
62840 KB |
Output is correct |
68 |
Correct |
783 ms |
54904 KB |
Output is correct |
69 |
Correct |
797 ms |
63092 KB |
Output is correct |
70 |
Correct |
750 ms |
45432 KB |
Output is correct |
71 |
Correct |
858 ms |
44600 KB |
Output is correct |
72 |
Correct |
768 ms |
50552 KB |
Output is correct |
73 |
Correct |
785 ms |
62584 KB |
Output is correct |
74 |
Correct |
787 ms |
62584 KB |
Output is correct |
75 |
Correct |
793 ms |
62656 KB |
Output is correct |
76 |
Correct |
805 ms |
63396 KB |
Output is correct |
77 |
Correct |
2 ms |
384 KB |
Output is correct |