Submission #617440

# Submission time Handle Problem Language Result Execution time Memory
617440 2022-08-01T11:20:36 Z patrikpavic2 Fish 2 (JOI22_fish2) C++17
100 / 100
1504 ms 43280 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define W Y.X
#define Z Y.Y
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pll;
typedef pair < ll, pll > str;
typedef vector < str > vstr;

const int N = 1e5 + 500;
const int OFF = (1 << 17);

vstr Tl[2 * OFF], Tr[2 * OFF];
int A[N], n;

void print(vstr &v){
	for(str &tmp : v) printf(" (%lld %lld %lld), ", tmp.X, tmp.W, tmp.Z);
	printf("\n");
}

void mrg(vstr &Al, vstr &Ar, vstr &Bl, vstr &C){
	if((int)Al.size() == 0) {C = Bl; return; }
	if((int)Bl.size() == 0) {C = Al; return; }
	//printf("Al : "); print(Al);
	//printf("Ar : "); print(Ar);
	//printf("Bl : "); print(Bl);
	C.clear();
	int gd = 0, uzA = 1, uzB = 0;
	ll cur = Ar[0].X;
	for(;1;){ // popravljam Al
		bool nes = 0;
		while(uzA < (int)Ar.size() && cur >= Ar[uzA].Z)
			cur += Ar[uzA].X - Ar[uzA - 1].X, uzA++, nes = 1;
		while(uzB < (int)Bl.size() && cur >= Bl[uzB].Z)
			cur += Bl[uzB].X - (uzB ? Bl[uzB - 1].X : 0), uzB++, nes = 1;
		if(uzA == (int)Ar.size())
			break;
		else if(!nes){
			cur += Ar[uzA].X - Ar[uzA - 1].X;
			gd = uzA++;
		}
	}
	int gd2 = 0; uzA = 0, uzB = 1;
	cur = Bl[0].X;
	for(;1;){ // barem tolko s Br kraja
		bool nes = 0;
		while(uzA < (int)Ar.size() && cur >= Ar[uzA].Z)
			cur += Ar[uzA].X - (uzA ? Ar[uzA - 1].X : 0), uzA++, nes = 1;
		while(uzB < (int)Bl.size() && cur >= Bl[uzB].Z)
			cur += Bl[uzB].X - Bl[uzB - 1].X, uzB++, nes = 1;
		if(uzA == (int)Ar.size())
			break;
		else if(!nes){
			if(uzB == (int)Bl.size()){
				gd2 = N; break;
			}
			cur += Bl[uzB].X - Bl[uzB - 1].X;
			gd2 = uzB++;
		}
	}
	int jos = 0;
	for(int i = gd;i + 1 < (int)Ar.size();i++)
		jos += Ar[i].W;
	for(int i = 0;i + 1 < (int)Al.size();i++)
		C.PB(Al[i]);
	cur = Al.back().X; ll trb = Al.back().Z;
	int kl = Al.back().W + jos;
	int dod = 0;
	for(;;){
		while(dod < (int)Bl.size() && cur >= Bl[dod].Z){
			cur += Bl[dod].X - (dod ? Bl[dod - 1].X : 0);
			if(dod >= gd2) 
				kl += Bl[dod].W;
			dod++;
		}
		C.PB({cur, {kl, trb}});
		if(dod == (int)Bl.size()) break;
		kl = (Bl[dod].X >= Al.back().Z ? Bl[dod].W : 0); trb = Bl[dod].Z;
		cur += Bl[dod].X - (dod ? Bl[dod - 1].X : 0);
		dod++; 	
	}
}

void update(int i, int x){
	A[i] = x;
	Tl[OFF + i] = {{A[i], {1, A[i]}}}; Tr[OFF + i] = Tl[OFF + i];
	for(i = (i + OFF) / 2 ; i ; i /= 2){
		mrg(Tl[2 * i], Tr[2 * i], Tl[2 * i + 1], Tl[i]);
		//print(Tl[i]);
		mrg(Tr[2 * i + 1], Tl[2 * i + 1], Tr[2 * i], Tr[i]);
		//print(Tr[i]);
	} 
}

vstr Ql, QQl;

void query(int i, int a, int b, int lo, int hi){
	if(lo <= a && b <= hi){
		mrg(Tl[i], Tr[i], Ql, QQl); 
		Ql = QQl; return;
	}
	if(a > hi || b < lo) return;
	query(2 * i + 1, (a + b) / 2 + 1, b, lo, hi);
	query(2 * i, a, (a + b) / 2, lo, hi);
}

int main(){
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", A + i);
		Tl[OFF + i] = {{A[i], {1, A[i]}}}; Tr[OFF + i] = Tl[OFF + i];		
	}
	for(int i = OFF - 1 ; i ; i--){
	//	printf("spajam u %d\n", i);
		//printf("T[ %d ] : \n", i);
		mrg(Tl[2 * i], Tr[2 * i], Tl[2 * i + 1], Tl[i]);
		//print(Tl[i]);
		mrg(Tr[2 * i + 1], Tl[2 * i + 1], Tr[2 * i], Tr[i]);
		//print(Tr[i]);
	}
	int q; scanf("%d", &q);
	for(;q--;){
		int ty; scanf("%d", &ty);
		if(ty == 1){
			int pos, x; scanf("%d%d", &pos, &x);
			update(pos - 1, x);
		}
		else{
			int l, r; scanf("%d%d", &l, &r); l--, r--;
			Ql.clear(); QQl.clear();
			query(1, 0, OFF - 1, l, r);
			printf("%d\n", Ql.back().W);
		}
	}
	return 0;
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:141:13: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  141 |    printf("%d\n", Ql.back().W);
      |            ~^
      |             |
      |             int
      |            %lld
fish2.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
fish2.cpp:119:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
fish2.cpp:130:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |  int q; scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
fish2.cpp:132:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |   int ty; scanf("%d", &ty);
      |           ~~~~~^~~~~~~~~~~
fish2.cpp:134:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |    int pos, x; scanf("%d%d", &pos, &x);
      |                ~~~~~^~~~~~~~~~~~~~~~~~
fish2.cpp:138:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |    int l, r; scanf("%d%d", &l, &r); l--, r--;
      |              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12500 KB Output is correct
2 Correct 9 ms 12604 KB Output is correct
3 Correct 10 ms 12600 KB Output is correct
4 Correct 11 ms 12536 KB Output is correct
5 Correct 13 ms 12628 KB Output is correct
6 Correct 14 ms 12732 KB Output is correct
7 Correct 12 ms 12628 KB Output is correct
8 Correct 11 ms 12696 KB Output is correct
9 Correct 12 ms 12632 KB Output is correct
10 Correct 14 ms 12672 KB Output is correct
11 Correct 13 ms 12628 KB Output is correct
12 Correct 15 ms 12608 KB Output is correct
13 Correct 11 ms 12668 KB Output is correct
14 Correct 15 ms 12628 KB Output is correct
15 Correct 14 ms 12744 KB Output is correct
16 Correct 10 ms 12720 KB Output is correct
17 Correct 11 ms 12636 KB Output is correct
18 Correct 21 ms 12628 KB Output is correct
19 Correct 11 ms 12676 KB Output is correct
20 Correct 10 ms 12708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12500 KB Output is correct
2 Correct 74 ms 36116 KB Output is correct
3 Correct 68 ms 34944 KB Output is correct
4 Correct 70 ms 35872 KB Output is correct
5 Correct 88 ms 35132 KB Output is correct
6 Correct 58 ms 29368 KB Output is correct
7 Correct 99 ms 29492 KB Output is correct
8 Correct 68 ms 29420 KB Output is correct
9 Correct 75 ms 29516 KB Output is correct
10 Correct 74 ms 37152 KB Output is correct
11 Correct 81 ms 33540 KB Output is correct
12 Correct 52 ms 29108 KB Output is correct
13 Correct 55 ms 29124 KB Output is correct
14 Correct 59 ms 30940 KB Output is correct
15 Correct 64 ms 30872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12500 KB Output is correct
2 Correct 9 ms 12604 KB Output is correct
3 Correct 10 ms 12600 KB Output is correct
4 Correct 11 ms 12536 KB Output is correct
5 Correct 13 ms 12628 KB Output is correct
6 Correct 14 ms 12732 KB Output is correct
7 Correct 12 ms 12628 KB Output is correct
8 Correct 11 ms 12696 KB Output is correct
9 Correct 12 ms 12632 KB Output is correct
10 Correct 14 ms 12672 KB Output is correct
11 Correct 13 ms 12628 KB Output is correct
12 Correct 15 ms 12608 KB Output is correct
13 Correct 11 ms 12668 KB Output is correct
14 Correct 15 ms 12628 KB Output is correct
15 Correct 14 ms 12744 KB Output is correct
16 Correct 10 ms 12720 KB Output is correct
17 Correct 11 ms 12636 KB Output is correct
18 Correct 21 ms 12628 KB Output is correct
19 Correct 11 ms 12676 KB Output is correct
20 Correct 10 ms 12708 KB Output is correct
21 Correct 8 ms 12500 KB Output is correct
22 Correct 74 ms 36116 KB Output is correct
23 Correct 68 ms 34944 KB Output is correct
24 Correct 70 ms 35872 KB Output is correct
25 Correct 88 ms 35132 KB Output is correct
26 Correct 58 ms 29368 KB Output is correct
27 Correct 99 ms 29492 KB Output is correct
28 Correct 68 ms 29420 KB Output is correct
29 Correct 75 ms 29516 KB Output is correct
30 Correct 74 ms 37152 KB Output is correct
31 Correct 81 ms 33540 KB Output is correct
32 Correct 52 ms 29108 KB Output is correct
33 Correct 55 ms 29124 KB Output is correct
34 Correct 59 ms 30940 KB Output is correct
35 Correct 64 ms 30872 KB Output is correct
36 Correct 103 ms 36128 KB Output is correct
37 Correct 110 ms 35088 KB Output is correct
38 Correct 92 ms 34964 KB Output is correct
39 Correct 78 ms 36216 KB Output is correct
40 Correct 84 ms 34892 KB Output is correct
41 Correct 74 ms 29464 KB Output is correct
42 Correct 63 ms 29460 KB Output is correct
43 Correct 71 ms 29800 KB Output is correct
44 Correct 87 ms 29692 KB Output is correct
45 Correct 90 ms 37364 KB Output is correct
46 Correct 98 ms 37272 KB Output is correct
47 Correct 99 ms 32756 KB Output is correct
48 Correct 70 ms 29272 KB Output is correct
49 Correct 57 ms 29128 KB Output is correct
50 Correct 68 ms 30832 KB Output is correct
51 Correct 90 ms 30924 KB Output is correct
52 Correct 75 ms 30776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12500 KB Output is correct
2 Correct 74 ms 36116 KB Output is correct
3 Correct 68 ms 34944 KB Output is correct
4 Correct 70 ms 35872 KB Output is correct
5 Correct 88 ms 35132 KB Output is correct
6 Correct 58 ms 29368 KB Output is correct
7 Correct 99 ms 29492 KB Output is correct
8 Correct 68 ms 29420 KB Output is correct
9 Correct 75 ms 29516 KB Output is correct
10 Correct 74 ms 37152 KB Output is correct
11 Correct 81 ms 33540 KB Output is correct
12 Correct 52 ms 29108 KB Output is correct
13 Correct 55 ms 29124 KB Output is correct
14 Correct 59 ms 30940 KB Output is correct
15 Correct 64 ms 30872 KB Output is correct
16 Correct 11 ms 12600 KB Output is correct
17 Correct 941 ms 35496 KB Output is correct
18 Correct 679 ms 36524 KB Output is correct
19 Correct 707 ms 35528 KB Output is correct
20 Correct 800 ms 35200 KB Output is correct
21 Correct 715 ms 36964 KB Output is correct
22 Correct 731 ms 38372 KB Output is correct
23 Correct 735 ms 36808 KB Output is correct
24 Correct 765 ms 36988 KB Output is correct
25 Correct 905 ms 37008 KB Output is correct
26 Correct 750 ms 36956 KB Output is correct
27 Correct 474 ms 32248 KB Output is correct
28 Correct 390 ms 32252 KB Output is correct
29 Correct 370 ms 32224 KB Output is correct
30 Correct 487 ms 31356 KB Output is correct
31 Correct 532 ms 31396 KB Output is correct
32 Correct 794 ms 35296 KB Output is correct
33 Correct 1071 ms 39736 KB Output is correct
34 Correct 658 ms 34844 KB Output is correct
35 Correct 691 ms 34216 KB Output is correct
36 Correct 880 ms 39624 KB Output is correct
37 Correct 358 ms 30868 KB Output is correct
38 Correct 371 ms 30988 KB Output is correct
39 Correct 491 ms 33300 KB Output is correct
40 Correct 483 ms 33336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12500 KB Output is correct
2 Correct 74 ms 36116 KB Output is correct
3 Correct 68 ms 34944 KB Output is correct
4 Correct 70 ms 35872 KB Output is correct
5 Correct 88 ms 35132 KB Output is correct
6 Correct 58 ms 29368 KB Output is correct
7 Correct 99 ms 29492 KB Output is correct
8 Correct 68 ms 29420 KB Output is correct
9 Correct 75 ms 29516 KB Output is correct
10 Correct 74 ms 37152 KB Output is correct
11 Correct 81 ms 33540 KB Output is correct
12 Correct 52 ms 29108 KB Output is correct
13 Correct 55 ms 29124 KB Output is correct
14 Correct 59 ms 30940 KB Output is correct
15 Correct 64 ms 30872 KB Output is correct
16 Correct 11 ms 12600 KB Output is correct
17 Correct 726 ms 37628 KB Output is correct
18 Correct 757 ms 40060 KB Output is correct
19 Correct 645 ms 35276 KB Output is correct
20 Correct 548 ms 39584 KB Output is correct
21 Correct 663 ms 37656 KB Output is correct
22 Correct 643 ms 40032 KB Output is correct
23 Correct 955 ms 35316 KB Output is correct
24 Correct 707 ms 39852 KB Output is correct
25 Correct 752 ms 35348 KB Output is correct
26 Correct 319 ms 31984 KB Output is correct
27 Correct 375 ms 32404 KB Output is correct
28 Correct 470 ms 35108 KB Output is correct
29 Correct 402 ms 32084 KB Output is correct
30 Correct 476 ms 32388 KB Output is correct
31 Correct 569 ms 35512 KB Output is correct
32 Correct 561 ms 38684 KB Output is correct
33 Correct 649 ms 33452 KB Output is correct
34 Correct 605 ms 41268 KB Output is correct
35 Correct 598 ms 37456 KB Output is correct
36 Correct 560 ms 38028 KB Output is correct
37 Correct 497 ms 34528 KB Output is correct
38 Correct 348 ms 33520 KB Output is correct
39 Correct 373 ms 34088 KB Output is correct
40 Correct 215 ms 32812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12500 KB Output is correct
2 Correct 9 ms 12604 KB Output is correct
3 Correct 10 ms 12600 KB Output is correct
4 Correct 11 ms 12536 KB Output is correct
5 Correct 13 ms 12628 KB Output is correct
6 Correct 14 ms 12732 KB Output is correct
7 Correct 12 ms 12628 KB Output is correct
8 Correct 11 ms 12696 KB Output is correct
9 Correct 12 ms 12632 KB Output is correct
10 Correct 14 ms 12672 KB Output is correct
11 Correct 13 ms 12628 KB Output is correct
12 Correct 15 ms 12608 KB Output is correct
13 Correct 11 ms 12668 KB Output is correct
14 Correct 15 ms 12628 KB Output is correct
15 Correct 14 ms 12744 KB Output is correct
16 Correct 10 ms 12720 KB Output is correct
17 Correct 11 ms 12636 KB Output is correct
18 Correct 21 ms 12628 KB Output is correct
19 Correct 11 ms 12676 KB Output is correct
20 Correct 10 ms 12708 KB Output is correct
21 Correct 8 ms 12500 KB Output is correct
22 Correct 74 ms 36116 KB Output is correct
23 Correct 68 ms 34944 KB Output is correct
24 Correct 70 ms 35872 KB Output is correct
25 Correct 88 ms 35132 KB Output is correct
26 Correct 58 ms 29368 KB Output is correct
27 Correct 99 ms 29492 KB Output is correct
28 Correct 68 ms 29420 KB Output is correct
29 Correct 75 ms 29516 KB Output is correct
30 Correct 74 ms 37152 KB Output is correct
31 Correct 81 ms 33540 KB Output is correct
32 Correct 52 ms 29108 KB Output is correct
33 Correct 55 ms 29124 KB Output is correct
34 Correct 59 ms 30940 KB Output is correct
35 Correct 64 ms 30872 KB Output is correct
36 Correct 103 ms 36128 KB Output is correct
37 Correct 110 ms 35088 KB Output is correct
38 Correct 92 ms 34964 KB Output is correct
39 Correct 78 ms 36216 KB Output is correct
40 Correct 84 ms 34892 KB Output is correct
41 Correct 74 ms 29464 KB Output is correct
42 Correct 63 ms 29460 KB Output is correct
43 Correct 71 ms 29800 KB Output is correct
44 Correct 87 ms 29692 KB Output is correct
45 Correct 90 ms 37364 KB Output is correct
46 Correct 98 ms 37272 KB Output is correct
47 Correct 99 ms 32756 KB Output is correct
48 Correct 70 ms 29272 KB Output is correct
49 Correct 57 ms 29128 KB Output is correct
50 Correct 68 ms 30832 KB Output is correct
51 Correct 90 ms 30924 KB Output is correct
52 Correct 75 ms 30776 KB Output is correct
53 Correct 11 ms 12600 KB Output is correct
54 Correct 941 ms 35496 KB Output is correct
55 Correct 679 ms 36524 KB Output is correct
56 Correct 707 ms 35528 KB Output is correct
57 Correct 800 ms 35200 KB Output is correct
58 Correct 715 ms 36964 KB Output is correct
59 Correct 731 ms 38372 KB Output is correct
60 Correct 735 ms 36808 KB Output is correct
61 Correct 765 ms 36988 KB Output is correct
62 Correct 905 ms 37008 KB Output is correct
63 Correct 750 ms 36956 KB Output is correct
64 Correct 474 ms 32248 KB Output is correct
65 Correct 390 ms 32252 KB Output is correct
66 Correct 370 ms 32224 KB Output is correct
67 Correct 487 ms 31356 KB Output is correct
68 Correct 532 ms 31396 KB Output is correct
69 Correct 794 ms 35296 KB Output is correct
70 Correct 1071 ms 39736 KB Output is correct
71 Correct 658 ms 34844 KB Output is correct
72 Correct 691 ms 34216 KB Output is correct
73 Correct 880 ms 39624 KB Output is correct
74 Correct 358 ms 30868 KB Output is correct
75 Correct 371 ms 30988 KB Output is correct
76 Correct 491 ms 33300 KB Output is correct
77 Correct 483 ms 33336 KB Output is correct
78 Correct 11 ms 12600 KB Output is correct
79 Correct 726 ms 37628 KB Output is correct
80 Correct 757 ms 40060 KB Output is correct
81 Correct 645 ms 35276 KB Output is correct
82 Correct 548 ms 39584 KB Output is correct
83 Correct 663 ms 37656 KB Output is correct
84 Correct 643 ms 40032 KB Output is correct
85 Correct 955 ms 35316 KB Output is correct
86 Correct 707 ms 39852 KB Output is correct
87 Correct 752 ms 35348 KB Output is correct
88 Correct 319 ms 31984 KB Output is correct
89 Correct 375 ms 32404 KB Output is correct
90 Correct 470 ms 35108 KB Output is correct
91 Correct 402 ms 32084 KB Output is correct
92 Correct 476 ms 32388 KB Output is correct
93 Correct 569 ms 35512 KB Output is correct
94 Correct 561 ms 38684 KB Output is correct
95 Correct 649 ms 33452 KB Output is correct
96 Correct 605 ms 41268 KB Output is correct
97 Correct 598 ms 37456 KB Output is correct
98 Correct 560 ms 38028 KB Output is correct
99 Correct 497 ms 34528 KB Output is correct
100 Correct 348 ms 33520 KB Output is correct
101 Correct 373 ms 34088 KB Output is correct
102 Correct 215 ms 32812 KB Output is correct
103 Correct 1504 ms 36632 KB Output is correct
104 Correct 586 ms 43280 KB Output is correct
105 Correct 718 ms 37300 KB Output is correct
106 Correct 611 ms 38820 KB Output is correct
107 Correct 1046 ms 36856 KB Output is correct
108 Correct 766 ms 43104 KB Output is correct
109 Correct 900 ms 37072 KB Output is correct
110 Correct 548 ms 40136 KB Output is correct
111 Correct 720 ms 37100 KB Output is correct
112 Correct 666 ms 38584 KB Output is correct
113 Correct 409 ms 34708 KB Output is correct
114 Correct 362 ms 32704 KB Output is correct
115 Correct 616 ms 37384 KB Output is correct
116 Correct 687 ms 36152 KB Output is correct
117 Correct 343 ms 33196 KB Output is correct
118 Correct 608 ms 33940 KB Output is correct
119 Correct 399 ms 35108 KB Output is correct
120 Correct 728 ms 37128 KB Output is correct
121 Correct 622 ms 35648 KB Output is correct
122 Correct 594 ms 40716 KB Output is correct
123 Correct 774 ms 35312 KB Output is correct
124 Correct 582 ms 37216 KB Output is correct
125 Correct 656 ms 33936 KB Output is correct
126 Correct 659 ms 36160 KB Output is correct
127 Correct 617 ms 36128 KB Output is correct
128 Correct 500 ms 32896 KB Output is correct
129 Correct 536 ms 36208 KB Output is correct
130 Correct 440 ms 34748 KB Output is correct