Submission #951619

# Submission time Handle Problem Language Result Execution time Memory
951619 2024-03-22T07:44:02 Z pcc Fish 2 (JOI22_fish2) C++17
25 / 100
1054 ms 11388 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 1e5+10;

int N,Q;
ll arr[mxn];

namespace S1{

	int calc(vector<int> &v){
		int ans = 0;
		for(int i = 0;i<v.size();i++){
			int l = i,r = i;
			ll sum = v[i];
			while((l>0&&sum>=v[l-1])||(r+1<v.size()&&sum>=v[r+1])){
				if(l>0&&sum>=v[l-1]){
					l--;
					sum += v[l];
				}
				else{
					r++;
					sum += v[r];
				}
			}
			if(l == 0&&r+1 == v.size())ans++;
		}
		return ans;
	}

	void solve(){
		while(Q--){
			int l,r,t;
			cin>>t>>l>>r;
			if(t == 1){
				arr[l] = r;
				continue;
			}
			vector<int> v;
			for(int i = l;i<=r;i++)v.push_back(arr[i]);
			cout<<calc(v)<<'\n';
		}
		return;
	}
}

namespace S2{
	pii seg[mxn*4];

#define ls now*2+1
#define rs now*2+2
#define mid ((l+r)>>1)
	void build(int now,int l,int r){
		if(l == r){
			seg[now] = pii(arr[l],l);
			return;
		}
		build(ls,l,mid);
		build(rs,mid+1,r);
		seg[now] = max(seg[ls],seg[rs]);
	}
	pii getbig(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r)return seg[now];
		if(mid>=e)return getbig(ls,l,mid,s,e);
		else if(mid<s)return getbig(rs,mid+1,r,s,e);
		else return max(getbig(ls,l,mid,s,e),getbig(rs,mid+1,r,s,e));
	}
#undef ls
#undef rs
#undef mid

	int ans = 0;
	ll pref[mxn];
	set<int> fail;
	set<int> st;
	vector<pii> v;
	void solve(){
		for(int i = 1;i<=N;i++)pref[i] = pref[i-1]+arr[i];
		arr[0] = arr[N+1] = 1e18;
		for(int i = 1;i<=N;i++)v.push_back(pii(arr[i],i));
		sort(v.rbegin(),v.rend());
		st.insert(v[0].sc);
		st.insert(0);
		st.insert(N+1);
		int ans = 1;
		for(int i = 1;i<N;i++){
			auto now = v[i].sc;
			if(fail.find(now) != fail.end())continue;
			auto lit = --st.lower_bound(now);
			auto rit = st.lower_bound(now);
			int s = *lit+1,e = *rit-1;
			if(pref[e]-pref[s-1]>=min(arr[*lit],arr[*rit])){
				ans++;
				st.insert(now);
			}
			else{
				for(int i = s;i<=e;i++)fail.insert(i);
			}
		}
		cout<<ans<<'\n';
		return;
	}
}

namespace S3{
	bitset<mxn> ban;
	ll pref[mxn];
	deque<int> dq;
	pii ch[mxn];
	int dfs(int now,int l,int r){
		if(!now)return 0;
		//cerr<<now<<":"<<l<<','<<r<<','<<ch[now].fs<<' '<<ch[now].sc<<endl;
		int re = 1;
		if(l != now&&pref[now-1]-pref[l-1]>=arr[now])re += dfs(ch[now].fs,l,now-1);
		if(r != now&&pref[r]-pref[now]>=arr[now])re += dfs(ch[now].sc,now+1,r);
		return re;
	}
	int calc(int l,int r){
		dq.clear();
		for(int i = l;i<=r;i++)ch[i].fs = ch[i].sc = 0;
		for(int i = l;i<=r;i++){
			while(!dq.empty()&&arr[dq.back()]<=arr[i]){
				ch[i].fs = dq.back();
				dq.pop_back();
			}
			if(!dq.empty())ch[dq.back()].sc = i;
			dq.push_back(i);
		}
		int ans = dfs(dq[0],l,r);
		return ans;
	}
	void solve(){
		for(int i = 1;i<=N;i++){
			pref[i] = pref[i-1]+arr[i];
		}
		while(Q--){
			int t,l,r;
			cin>>t>>l>>r;
			if(t == 1){
				arr[l] = r;
				for(int i = l;i<=N;i++)pref[i] = pref[i-1]+arr[i];
				continue;
			}
			cout<<calc(l,r)<<'\n';
		}
		return;
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	for(int i = 1;i<=N;i++)cin>>arr[i];
	cin>>Q;
	if(N<=500&&Q<=500)S1::solve();
	else if(Q<=1000)S3::solve();
	else S2::solve();
}

Compilation message

fish2.cpp: In function 'int S1::calc(std::vector<int>&)':
fish2.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   for(int i = 0;i<v.size();i++){
      |                 ~^~~~~~~~~
fish2.cpp:22:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |    while((l>0&&sum>=v[l-1])||(r+1<v.size()&&sum>=v[r+1])){
      |                               ~~~^~~~~~~~~
fish2.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    if(l == 0&&r+1 == v.size())ans++;
      |               ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2516 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 4 ms 2396 KB Output is correct
6 Correct 4 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 8 ms 2396 KB Output is correct
10 Correct 5 ms 2396 KB Output is correct
11 Correct 13 ms 2540 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 11 ms 2536 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 4 ms 2484 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 30 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 8 ms 3960 KB Output is correct
3 Correct 7 ms 3676 KB Output is correct
4 Correct 11 ms 3876 KB Output is correct
5 Correct 7 ms 3672 KB Output is correct
6 Correct 11 ms 4264 KB Output is correct
7 Correct 7 ms 3676 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 7 ms 3420 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 6 ms 3700 KB Output is correct
12 Correct 7 ms 3672 KB Output is correct
13 Correct 7 ms 3672 KB Output is correct
14 Correct 8 ms 4184 KB Output is correct
15 Correct 9 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2516 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 4 ms 2396 KB Output is correct
6 Correct 4 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 8 ms 2396 KB Output is correct
10 Correct 5 ms 2396 KB Output is correct
11 Correct 13 ms 2540 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 11 ms 2536 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 4 ms 2484 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 30 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 8 ms 3960 KB Output is correct
23 Correct 7 ms 3676 KB Output is correct
24 Correct 11 ms 3876 KB Output is correct
25 Correct 7 ms 3672 KB Output is correct
26 Correct 11 ms 4264 KB Output is correct
27 Correct 7 ms 3676 KB Output is correct
28 Correct 12 ms 4188 KB Output is correct
29 Correct 7 ms 3420 KB Output is correct
30 Correct 10 ms 3932 KB Output is correct
31 Correct 6 ms 3700 KB Output is correct
32 Correct 7 ms 3672 KB Output is correct
33 Correct 7 ms 3672 KB Output is correct
34 Correct 8 ms 4184 KB Output is correct
35 Correct 9 ms 4184 KB Output is correct
36 Correct 162 ms 4248 KB Output is correct
37 Correct 204 ms 3796 KB Output is correct
38 Correct 182 ms 3800 KB Output is correct
39 Correct 146 ms 4180 KB Output is correct
40 Correct 198 ms 3792 KB Output is correct
41 Correct 455 ms 4428 KB Output is correct
42 Correct 548 ms 4432 KB Output is correct
43 Correct 304 ms 3676 KB Output is correct
44 Correct 320 ms 3668 KB Output is correct
45 Correct 170 ms 4288 KB Output is correct
46 Correct 222 ms 3928 KB Output is correct
47 Correct 216 ms 3676 KB Output is correct
48 Correct 201 ms 3920 KB Output is correct
49 Correct 381 ms 3780 KB Output is correct
50 Correct 269 ms 4360 KB Output is correct
51 Correct 995 ms 4616 KB Output is correct
52 Correct 1054 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 8 ms 3960 KB Output is correct
3 Correct 7 ms 3676 KB Output is correct
4 Correct 11 ms 3876 KB Output is correct
5 Correct 7 ms 3672 KB Output is correct
6 Correct 11 ms 4264 KB Output is correct
7 Correct 7 ms 3676 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 7 ms 3420 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 6 ms 3700 KB Output is correct
12 Correct 7 ms 3672 KB Output is correct
13 Correct 7 ms 3672 KB Output is correct
14 Correct 8 ms 4184 KB Output is correct
15 Correct 9 ms 4184 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Incorrect 35 ms 11224 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 8 ms 3960 KB Output is correct
3 Correct 7 ms 3676 KB Output is correct
4 Correct 11 ms 3876 KB Output is correct
5 Correct 7 ms 3672 KB Output is correct
6 Correct 11 ms 4264 KB Output is correct
7 Correct 7 ms 3676 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 7 ms 3420 KB Output is correct
10 Correct 10 ms 3932 KB Output is correct
11 Correct 6 ms 3700 KB Output is correct
12 Correct 7 ms 3672 KB Output is correct
13 Correct 7 ms 3672 KB Output is correct
14 Correct 8 ms 4184 KB Output is correct
15 Correct 9 ms 4184 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Incorrect 45 ms 11388 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2516 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 4 ms 2396 KB Output is correct
6 Correct 4 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 8 ms 2396 KB Output is correct
10 Correct 5 ms 2396 KB Output is correct
11 Correct 13 ms 2540 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 11 ms 2536 KB Output is correct
17 Correct 2 ms 2392 KB Output is correct
18 Correct 4 ms 2484 KB Output is correct
19 Correct 5 ms 2396 KB Output is correct
20 Correct 30 ms 2396 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 8 ms 3960 KB Output is correct
23 Correct 7 ms 3676 KB Output is correct
24 Correct 11 ms 3876 KB Output is correct
25 Correct 7 ms 3672 KB Output is correct
26 Correct 11 ms 4264 KB Output is correct
27 Correct 7 ms 3676 KB Output is correct
28 Correct 12 ms 4188 KB Output is correct
29 Correct 7 ms 3420 KB Output is correct
30 Correct 10 ms 3932 KB Output is correct
31 Correct 6 ms 3700 KB Output is correct
32 Correct 7 ms 3672 KB Output is correct
33 Correct 7 ms 3672 KB Output is correct
34 Correct 8 ms 4184 KB Output is correct
35 Correct 9 ms 4184 KB Output is correct
36 Correct 162 ms 4248 KB Output is correct
37 Correct 204 ms 3796 KB Output is correct
38 Correct 182 ms 3800 KB Output is correct
39 Correct 146 ms 4180 KB Output is correct
40 Correct 198 ms 3792 KB Output is correct
41 Correct 455 ms 4428 KB Output is correct
42 Correct 548 ms 4432 KB Output is correct
43 Correct 304 ms 3676 KB Output is correct
44 Correct 320 ms 3668 KB Output is correct
45 Correct 170 ms 4288 KB Output is correct
46 Correct 222 ms 3928 KB Output is correct
47 Correct 216 ms 3676 KB Output is correct
48 Correct 201 ms 3920 KB Output is correct
49 Correct 381 ms 3780 KB Output is correct
50 Correct 269 ms 4360 KB Output is correct
51 Correct 995 ms 4616 KB Output is correct
52 Correct 1054 ms 4432 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Incorrect 35 ms 11224 KB Output isn't correct
55 Halted 0 ms 0 KB -