Submission #546367

# Submission time Handle Problem Language Result Execution time Memory
546367 2022-04-07T11:31:09 Z ivan_tudor Fish 2 (JOI22_fish2) C++14
100 / 100
1366 ms 74296 KB
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct stuck{
  int i;
  long long a;
  long long sum;
  int candi;
};
struct aint_node{
  vector<stuck> pref;
  vector<stuck> suf;
  long long sum;
  int answer;
};
const long long INF = LLONG_MAX;
aint_node join(aint_node l, aint_node r, int litv, int ritv){
  aint_node root;
  root.sum = l.sum + r.sum;
 /// folosim l.suf, r.pref
  int isuf = 0, jpref = 0;
  int candidates = 0;
  long long csum = 0;
  vector<int> newlscand(l.suf.size());
  vector<int> newrpcand(r.pref.size());
  stuck left = l.suf[0], right = r.pref[0];
  while(true ){
    if(isuf + 1 >= l.suf.size() && jpref + 1 >= r.pref.size())
			break;
		if(isuf + 1 < l.suf.size() && jpref + 1 < r.pref.size()){
			if(l.suf[isuf].a <= r.pref[jpref].a){
				isuf++;
				left = l.suf[isuf];
				candidates += left.candi;
			}
			else{
				jpref++;
				right = r.pref[jpref];
				candidates += right.candi;
			}
    }
    else{
			if(isuf + 1 < l.suf.size()){
				isuf++;
				left = l.suf[isuf];
				candidates += left.candi;
			}
			else if(jpref + 1 < r.pref.size()){
				jpref++;
				right = r.pref[jpref];
				candidates += right.candi;
			}
    }
    csum = left.sum + right.sum; /// pana aici am ajuns
    if(left.i == litv - 1){
			newrpcand[jpref] = candidates;
    }
    if(right.i == ritv + 1){
			newlscand[isuf] = candidates;
    }
    if(csum < min(left.a, right.a) && min(left.a, right.a) < INF)
      candidates = 0;
  }
  root.answer = candidates;
  ///todothis
  root.pref = l.pref;
  root.pref.pop_back();
  for(int i = 0; i < r.pref.size(); i++){
    stuck x = r.pref[i];
    if(x.a > x.sum + l.sum){
      root.pref.push_back({x.i, x.a, x.sum + l.sum, newrpcand[i] });
    }
  }
	//root.pref.push_back({ritv + 1, INF, root.sum, root.answer});
  root.suf = r.suf;
  root.suf.pop_back(); /// cel de la margine
  for(int i = 0; i < l.suf.size(); i++){
		stuck x = l.suf[i];
		if(x.a > x.sum + r.sum){
			root.suf.push_back({x.i, x.a, x.sum + r.sum, newlscand[i]});
		}
  }
  return root;
}
aint_node build(int poz, int val){
	aint_node rsp;
	rsp.sum = val;
	rsp.answer = 1;
	rsp.pref.push_back({poz, val, 0, 0});
	rsp.pref.push_back({poz + 1, INF, val, 1});
	rsp.suf.push_back({poz, val, 0, 0});
	rsp.suf.push_back({poz - 1, INF, val, 1});
	return rsp;
}
const int N = 100005;
aint_node aint[4*N];
int v[N];
void build_aint(int nod, int l, int r){
	if(l == r){
		aint[nod] = build(l, v[l]);
		return;
	}
	int mid = (l + r)/2;
	build_aint(2*nod, l, mid);
	build_aint(2*nod + 1, mid + 1, r);
	aint[nod] = join(aint[2*nod], aint[2*nod + 1], l, r);
}
void update(int nod, int l, int r, int poz, int val){
	if(poz > r || poz < l)
		return;
	if(l == r){
		aint[nod] = build(poz, val);
		return;
	}
	int mid = (l + r)/2;
	update(2*nod, l, mid, poz, val);
	update(2*nod + 1, mid + 1, r, poz, val);
	aint[nod] = join(aint[2*nod], aint[2*nod + 1], l, r);
}
aint_node query(int nod, int l, int r, int ql, int qr){
	if(ql <= l && r <= qr)
		return aint[nod];
	int mid = (l + r)/2;
	if(qr <= mid){
		return query(2*nod, l, mid, ql, qr);
	}
	if(ql >= mid + 1){
		return query(2*nod + 1, mid + 1, r, ql, qr);
	}
	aint_node ls = query(2*nod, l, mid, ql, mid);
	aint_node rs = query(2*nod + 1, mid + 1, r, mid + 1, qr);
	return join(ls, rs, ql, qr);
}
int main()
{
	int n;
	cin>>n;
	for(int i = 1; i<=n; i++)
		cin>>v[i];
	build_aint(1, 1, n);
	int q;
	cin>>q;
	for(int i = 1; i<=q; i++){
		int t;
		cin>>t;
		if(t == 1){
			int poz, val;
			cin>>poz>>val;
			update(1, 1, n, poz, val);
		}
		else{
			int l, r;
			cin>>l>>r;
			aint_node rsp = query(1, 1, n, l, r);
			cout<<rsp.answer<<"\n";
		}
	}
	return 0;
}

Compilation message

fish2.cpp: In function 'aint_node join(aint_node, aint_node, int, int)':
fish2.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(isuf + 1 >= l.suf.size() && jpref + 1 >= r.pref.size())
      |        ~~~~~~~~~^~~~~~~~~~~~~~~
fish2.cpp:28:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(isuf + 1 >= l.suf.size() && jpref + 1 >= r.pref.size())
      |                                    ~~~~~~~~~~^~~~~~~~~~~~~~~~
fish2.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(isuf + 1 < l.suf.size() && jpref + 1 < r.pref.size()){
      |      ~~~~~~~~~^~~~~~~~~~~~~~
fish2.cpp:30:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(isuf + 1 < l.suf.size() && jpref + 1 < r.pref.size()){
      |                                 ~~~~~~~~~~^~~~~~~~~~~~~~~
fish2.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |    if(isuf + 1 < l.suf.size()){
      |       ~~~~~~~~~^~~~~~~~~~~~~~
fish2.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    else if(jpref + 1 < r.pref.size()){
      |            ~~~~~~~~~~^~~~~~~~~~~~~~~
fish2.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(int i = 0; i < r.pref.size(); i++){
      |                  ~~^~~~~~~~~~~~~~~
fish2.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<stuck>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for(int i = 0; i < l.suf.size(); i++){
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25300 KB Output is correct
3 Correct 12 ms 25276 KB Output is correct
4 Correct 15 ms 25364 KB Output is correct
5 Correct 16 ms 25552 KB Output is correct
6 Correct 18 ms 25556 KB Output is correct
7 Correct 19 ms 25556 KB Output is correct
8 Correct 15 ms 25556 KB Output is correct
9 Correct 16 ms 25600 KB Output is correct
10 Correct 14 ms 25556 KB Output is correct
11 Correct 15 ms 25552 KB Output is correct
12 Correct 14 ms 25532 KB Output is correct
13 Correct 17 ms 25556 KB Output is correct
14 Correct 14 ms 25556 KB Output is correct
15 Correct 15 ms 25556 KB Output is correct
16 Correct 17 ms 25528 KB Output is correct
17 Correct 15 ms 25556 KB Output is correct
18 Correct 15 ms 25452 KB Output is correct
19 Correct 16 ms 25556 KB Output is correct
20 Correct 17 ms 25568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 150 ms 73572 KB Output is correct
3 Correct 134 ms 71792 KB Output is correct
4 Correct 135 ms 73432 KB Output is correct
5 Correct 164 ms 72004 KB Output is correct
6 Correct 143 ms 62884 KB Output is correct
7 Correct 120 ms 63208 KB Output is correct
8 Correct 134 ms 62924 KB Output is correct
9 Correct 122 ms 63236 KB Output is correct
10 Correct 143 ms 73588 KB Output is correct
11 Correct 128 ms 68428 KB Output is correct
12 Correct 113 ms 62480 KB Output is correct
13 Correct 128 ms 62356 KB Output is correct
14 Correct 134 ms 64904 KB Output is correct
15 Correct 139 ms 65172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25300 KB Output is correct
3 Correct 12 ms 25276 KB Output is correct
4 Correct 15 ms 25364 KB Output is correct
5 Correct 16 ms 25552 KB Output is correct
6 Correct 18 ms 25556 KB Output is correct
7 Correct 19 ms 25556 KB Output is correct
8 Correct 15 ms 25556 KB Output is correct
9 Correct 16 ms 25600 KB Output is correct
10 Correct 14 ms 25556 KB Output is correct
11 Correct 15 ms 25552 KB Output is correct
12 Correct 14 ms 25532 KB Output is correct
13 Correct 17 ms 25556 KB Output is correct
14 Correct 14 ms 25556 KB Output is correct
15 Correct 15 ms 25556 KB Output is correct
16 Correct 17 ms 25528 KB Output is correct
17 Correct 15 ms 25556 KB Output is correct
18 Correct 15 ms 25452 KB Output is correct
19 Correct 16 ms 25556 KB Output is correct
20 Correct 17 ms 25568 KB Output is correct
21 Correct 12 ms 25300 KB Output is correct
22 Correct 150 ms 73572 KB Output is correct
23 Correct 134 ms 71792 KB Output is correct
24 Correct 135 ms 73432 KB Output is correct
25 Correct 164 ms 72004 KB Output is correct
26 Correct 143 ms 62884 KB Output is correct
27 Correct 120 ms 63208 KB Output is correct
28 Correct 134 ms 62924 KB Output is correct
29 Correct 122 ms 63236 KB Output is correct
30 Correct 143 ms 73588 KB Output is correct
31 Correct 128 ms 68428 KB Output is correct
32 Correct 113 ms 62480 KB Output is correct
33 Correct 128 ms 62356 KB Output is correct
34 Correct 134 ms 64904 KB Output is correct
35 Correct 139 ms 65172 KB Output is correct
36 Correct 173 ms 73696 KB Output is correct
37 Correct 164 ms 72028 KB Output is correct
38 Correct 169 ms 71812 KB Output is correct
39 Correct 171 ms 73600 KB Output is correct
40 Correct 140 ms 71788 KB Output is correct
41 Correct 164 ms 63044 KB Output is correct
42 Correct 152 ms 62796 KB Output is correct
43 Correct 143 ms 63572 KB Output is correct
44 Correct 122 ms 63300 KB Output is correct
45 Correct 148 ms 73340 KB Output is correct
46 Correct 163 ms 73592 KB Output is correct
47 Correct 141 ms 67296 KB Output is correct
48 Correct 147 ms 62924 KB Output is correct
49 Correct 121 ms 62520 KB Output is correct
50 Correct 154 ms 65024 KB Output is correct
51 Correct 176 ms 65228 KB Output is correct
52 Correct 136 ms 65076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 150 ms 73572 KB Output is correct
3 Correct 134 ms 71792 KB Output is correct
4 Correct 135 ms 73432 KB Output is correct
5 Correct 164 ms 72004 KB Output is correct
6 Correct 143 ms 62884 KB Output is correct
7 Correct 120 ms 63208 KB Output is correct
8 Correct 134 ms 62924 KB Output is correct
9 Correct 122 ms 63236 KB Output is correct
10 Correct 143 ms 73588 KB Output is correct
11 Correct 128 ms 68428 KB Output is correct
12 Correct 113 ms 62480 KB Output is correct
13 Correct 128 ms 62356 KB Output is correct
14 Correct 134 ms 64904 KB Output is correct
15 Correct 139 ms 65172 KB Output is correct
16 Correct 11 ms 25304 KB Output is correct
17 Correct 1289 ms 72528 KB Output is correct
18 Correct 1274 ms 74296 KB Output is correct
19 Correct 1317 ms 72696 KB Output is correct
20 Correct 1358 ms 72048 KB Output is correct
21 Correct 1313 ms 72444 KB Output is correct
22 Correct 1226 ms 74268 KB Output is correct
23 Correct 1366 ms 72096 KB Output is correct
24 Correct 1316 ms 72416 KB Output is correct
25 Correct 1318 ms 72528 KB Output is correct
26 Correct 1322 ms 72340 KB Output is correct
27 Correct 1010 ms 63560 KB Output is correct
28 Correct 1020 ms 63516 KB Output is correct
29 Correct 1041 ms 63556 KB Output is correct
30 Correct 1159 ms 63684 KB Output is correct
31 Correct 1135 ms 63540 KB Output is correct
32 Correct 1313 ms 68788 KB Output is correct
33 Correct 1343 ms 74180 KB Output is correct
34 Correct 1282 ms 68116 KB Output is correct
35 Correct 1255 ms 66988 KB Output is correct
36 Correct 1294 ms 74068 KB Output is correct
37 Correct 984 ms 63064 KB Output is correct
38 Correct 962 ms 62856 KB Output is correct
39 Correct 1046 ms 65632 KB Output is correct
40 Correct 1137 ms 66028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 150 ms 73572 KB Output is correct
3 Correct 134 ms 71792 KB Output is correct
4 Correct 135 ms 73432 KB Output is correct
5 Correct 164 ms 72004 KB Output is correct
6 Correct 143 ms 62884 KB Output is correct
7 Correct 120 ms 63208 KB Output is correct
8 Correct 134 ms 62924 KB Output is correct
9 Correct 122 ms 63236 KB Output is correct
10 Correct 143 ms 73588 KB Output is correct
11 Correct 128 ms 68428 KB Output is correct
12 Correct 113 ms 62480 KB Output is correct
13 Correct 128 ms 62356 KB Output is correct
14 Correct 134 ms 64904 KB Output is correct
15 Correct 139 ms 65172 KB Output is correct
16 Correct 12 ms 25300 KB Output is correct
17 Correct 1149 ms 73896 KB Output is correct
18 Correct 1144 ms 72420 KB Output is correct
19 Correct 861 ms 72232 KB Output is correct
20 Correct 883 ms 72596 KB Output is correct
21 Correct 1079 ms 73720 KB Output is correct
22 Correct 1184 ms 72428 KB Output is correct
23 Correct 1039 ms 72184 KB Output is correct
24 Correct 1137 ms 72396 KB Output is correct
25 Correct 941 ms 72240 KB Output is correct
26 Correct 895 ms 63240 KB Output is correct
27 Correct 1020 ms 63204 KB Output is correct
28 Correct 898 ms 67156 KB Output is correct
29 Correct 926 ms 63456 KB Output is correct
30 Correct 1075 ms 63172 KB Output is correct
31 Correct 1051 ms 66972 KB Output is correct
32 Correct 1165 ms 69100 KB Output is correct
33 Correct 888 ms 68828 KB Output is correct
34 Correct 1159 ms 73892 KB Output is correct
35 Correct 811 ms 74080 KB Output is correct
36 Correct 1117 ms 68528 KB Output is correct
37 Correct 1016 ms 68076 KB Output is correct
38 Correct 728 ms 67828 KB Output is correct
39 Correct 880 ms 65728 KB Output is correct
40 Correct 507 ms 65960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25300 KB Output is correct
2 Correct 12 ms 25300 KB Output is correct
3 Correct 12 ms 25276 KB Output is correct
4 Correct 15 ms 25364 KB Output is correct
5 Correct 16 ms 25552 KB Output is correct
6 Correct 18 ms 25556 KB Output is correct
7 Correct 19 ms 25556 KB Output is correct
8 Correct 15 ms 25556 KB Output is correct
9 Correct 16 ms 25600 KB Output is correct
10 Correct 14 ms 25556 KB Output is correct
11 Correct 15 ms 25552 KB Output is correct
12 Correct 14 ms 25532 KB Output is correct
13 Correct 17 ms 25556 KB Output is correct
14 Correct 14 ms 25556 KB Output is correct
15 Correct 15 ms 25556 KB Output is correct
16 Correct 17 ms 25528 KB Output is correct
17 Correct 15 ms 25556 KB Output is correct
18 Correct 15 ms 25452 KB Output is correct
19 Correct 16 ms 25556 KB Output is correct
20 Correct 17 ms 25568 KB Output is correct
21 Correct 12 ms 25300 KB Output is correct
22 Correct 150 ms 73572 KB Output is correct
23 Correct 134 ms 71792 KB Output is correct
24 Correct 135 ms 73432 KB Output is correct
25 Correct 164 ms 72004 KB Output is correct
26 Correct 143 ms 62884 KB Output is correct
27 Correct 120 ms 63208 KB Output is correct
28 Correct 134 ms 62924 KB Output is correct
29 Correct 122 ms 63236 KB Output is correct
30 Correct 143 ms 73588 KB Output is correct
31 Correct 128 ms 68428 KB Output is correct
32 Correct 113 ms 62480 KB Output is correct
33 Correct 128 ms 62356 KB Output is correct
34 Correct 134 ms 64904 KB Output is correct
35 Correct 139 ms 65172 KB Output is correct
36 Correct 173 ms 73696 KB Output is correct
37 Correct 164 ms 72028 KB Output is correct
38 Correct 169 ms 71812 KB Output is correct
39 Correct 171 ms 73600 KB Output is correct
40 Correct 140 ms 71788 KB Output is correct
41 Correct 164 ms 63044 KB Output is correct
42 Correct 152 ms 62796 KB Output is correct
43 Correct 143 ms 63572 KB Output is correct
44 Correct 122 ms 63300 KB Output is correct
45 Correct 148 ms 73340 KB Output is correct
46 Correct 163 ms 73592 KB Output is correct
47 Correct 141 ms 67296 KB Output is correct
48 Correct 147 ms 62924 KB Output is correct
49 Correct 121 ms 62520 KB Output is correct
50 Correct 154 ms 65024 KB Output is correct
51 Correct 176 ms 65228 KB Output is correct
52 Correct 136 ms 65076 KB Output is correct
53 Correct 11 ms 25304 KB Output is correct
54 Correct 1289 ms 72528 KB Output is correct
55 Correct 1274 ms 74296 KB Output is correct
56 Correct 1317 ms 72696 KB Output is correct
57 Correct 1358 ms 72048 KB Output is correct
58 Correct 1313 ms 72444 KB Output is correct
59 Correct 1226 ms 74268 KB Output is correct
60 Correct 1366 ms 72096 KB Output is correct
61 Correct 1316 ms 72416 KB Output is correct
62 Correct 1318 ms 72528 KB Output is correct
63 Correct 1322 ms 72340 KB Output is correct
64 Correct 1010 ms 63560 KB Output is correct
65 Correct 1020 ms 63516 KB Output is correct
66 Correct 1041 ms 63556 KB Output is correct
67 Correct 1159 ms 63684 KB Output is correct
68 Correct 1135 ms 63540 KB Output is correct
69 Correct 1313 ms 68788 KB Output is correct
70 Correct 1343 ms 74180 KB Output is correct
71 Correct 1282 ms 68116 KB Output is correct
72 Correct 1255 ms 66988 KB Output is correct
73 Correct 1294 ms 74068 KB Output is correct
74 Correct 984 ms 63064 KB Output is correct
75 Correct 962 ms 62856 KB Output is correct
76 Correct 1046 ms 65632 KB Output is correct
77 Correct 1137 ms 66028 KB Output is correct
78 Correct 12 ms 25300 KB Output is correct
79 Correct 1149 ms 73896 KB Output is correct
80 Correct 1144 ms 72420 KB Output is correct
81 Correct 861 ms 72232 KB Output is correct
82 Correct 883 ms 72596 KB Output is correct
83 Correct 1079 ms 73720 KB Output is correct
84 Correct 1184 ms 72428 KB Output is correct
85 Correct 1039 ms 72184 KB Output is correct
86 Correct 1137 ms 72396 KB Output is correct
87 Correct 941 ms 72240 KB Output is correct
88 Correct 895 ms 63240 KB Output is correct
89 Correct 1020 ms 63204 KB Output is correct
90 Correct 898 ms 67156 KB Output is correct
91 Correct 926 ms 63456 KB Output is correct
92 Correct 1075 ms 63172 KB Output is correct
93 Correct 1051 ms 66972 KB Output is correct
94 Correct 1165 ms 69100 KB Output is correct
95 Correct 888 ms 68828 KB Output is correct
96 Correct 1159 ms 73892 KB Output is correct
97 Correct 811 ms 74080 KB Output is correct
98 Correct 1117 ms 68528 KB Output is correct
99 Correct 1016 ms 68076 KB Output is correct
100 Correct 728 ms 67828 KB Output is correct
101 Correct 880 ms 65728 KB Output is correct
102 Correct 507 ms 65960 KB Output is correct
103 Correct 1305 ms 72016 KB Output is correct
104 Correct 1329 ms 73840 KB Output is correct
105 Correct 1345 ms 72784 KB Output is correct
106 Correct 1237 ms 72732 KB Output is correct
107 Correct 1193 ms 72420 KB Output is correct
108 Correct 1221 ms 73696 KB Output is correct
109 Correct 1252 ms 72000 KB Output is correct
110 Correct 1197 ms 72552 KB Output is correct
111 Correct 1267 ms 72464 KB Output is correct
112 Correct 1188 ms 72364 KB Output is correct
113 Correct 1063 ms 63352 KB Output is correct
114 Correct 989 ms 63604 KB Output is correct
115 Correct 1126 ms 67180 KB Output is correct
116 Correct 1202 ms 67084 KB Output is correct
117 Correct 1040 ms 63888 KB Output is correct
118 Correct 1157 ms 66356 KB Output is correct
119 Correct 1041 ms 62968 KB Output is correct
120 Correct 1161 ms 67184 KB Output is correct
121 Correct 1171 ms 67188 KB Output is correct
122 Correct 1156 ms 69052 KB Output is correct
123 Correct 1091 ms 68844 KB Output is correct
124 Correct 1231 ms 68308 KB Output is correct
125 Correct 1146 ms 66500 KB Output is correct
126 Correct 1226 ms 67724 KB Output is correct
127 Correct 1162 ms 68044 KB Output is correct
128 Correct 1070 ms 65748 KB Output is correct
129 Correct 1080 ms 65576 KB Output is correct
130 Correct 1127 ms 65864 KB Output is correct