Submission #951551

# Submission time Handle Problem Language Result Execution time Memory
951551 2024-03-22T06:09:00 Z pcc Fish 2 (JOI22_fish2) C++17
13 / 100
67 ms 11400 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(){
		cin>>Q;
		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(){
		cin>>Q;
		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;
	}
}

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];
	if(N<=500&&Q<=500)S1::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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 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 7 ms 2396 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 12 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 4 ms 2392 KB Output is correct
14 Correct 3 ms 2392 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 11 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 26 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 43 ms 10436 KB Output is correct
3 Correct 39 ms 10704 KB Output is correct
4 Correct 46 ms 10960 KB Output is correct
5 Correct 35 ms 10780 KB Output is correct
6 Correct 67 ms 11380 KB Output is correct
7 Correct 38 ms 10652 KB Output is correct
8 Correct 63 ms 11400 KB Output is correct
9 Correct 37 ms 10700 KB Output is correct
10 Correct 51 ms 11056 KB Output is correct
11 Correct 32 ms 10700 KB Output is correct
12 Correct 37 ms 10704 KB Output is correct
13 Correct 38 ms 10624 KB Output is correct
14 Correct 42 ms 11212 KB Output is correct
15 Correct 50 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 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 7 ms 2396 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 12 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 4 ms 2392 KB Output is correct
14 Correct 3 ms 2392 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 11 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 26 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 43 ms 10436 KB Output is correct
23 Correct 39 ms 10704 KB Output is correct
24 Correct 46 ms 10960 KB Output is correct
25 Correct 35 ms 10780 KB Output is correct
26 Correct 67 ms 11380 KB Output is correct
27 Correct 38 ms 10652 KB Output is correct
28 Correct 63 ms 11400 KB Output is correct
29 Correct 37 ms 10700 KB Output is correct
30 Correct 51 ms 11056 KB Output is correct
31 Correct 32 ms 10700 KB Output is correct
32 Correct 37 ms 10704 KB Output is correct
33 Correct 38 ms 10624 KB Output is correct
34 Correct 42 ms 11212 KB Output is correct
35 Correct 50 ms 11212 KB Output is correct
36 Incorrect 34 ms 10976 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 43 ms 10436 KB Output is correct
3 Correct 39 ms 10704 KB Output is correct
4 Correct 46 ms 10960 KB Output is correct
5 Correct 35 ms 10780 KB Output is correct
6 Correct 67 ms 11380 KB Output is correct
7 Correct 38 ms 10652 KB Output is correct
8 Correct 63 ms 11400 KB Output is correct
9 Correct 37 ms 10700 KB Output is correct
10 Correct 51 ms 11056 KB Output is correct
11 Correct 32 ms 10700 KB Output is correct
12 Correct 37 ms 10704 KB Output is correct
13 Correct 38 ms 10624 KB Output is correct
14 Correct 42 ms 11212 KB Output is correct
15 Correct 50 ms 11212 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Incorrect 36 ms 11088 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 43 ms 10436 KB Output is correct
3 Correct 39 ms 10704 KB Output is correct
4 Correct 46 ms 10960 KB Output is correct
5 Correct 35 ms 10780 KB Output is correct
6 Correct 67 ms 11380 KB Output is correct
7 Correct 38 ms 10652 KB Output is correct
8 Correct 63 ms 11400 KB Output is correct
9 Correct 37 ms 10700 KB Output is correct
10 Correct 51 ms 11056 KB Output is correct
11 Correct 32 ms 10700 KB Output is correct
12 Correct 37 ms 10704 KB Output is correct
13 Correct 38 ms 10624 KB Output is correct
14 Correct 42 ms 11212 KB Output is correct
15 Correct 50 ms 11212 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Incorrect 45 ms 11220 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 3 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 7 ms 2396 KB Output is correct
10 Correct 5 ms 2392 KB Output is correct
11 Correct 12 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 4 ms 2392 KB Output is correct
14 Correct 3 ms 2392 KB Output is correct
15 Correct 3 ms 2516 KB Output is correct
16 Correct 11 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 4 ms 2396 KB Output is correct
19 Correct 4 ms 2396 KB Output is correct
20 Correct 26 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 43 ms 10436 KB Output is correct
23 Correct 39 ms 10704 KB Output is correct
24 Correct 46 ms 10960 KB Output is correct
25 Correct 35 ms 10780 KB Output is correct
26 Correct 67 ms 11380 KB Output is correct
27 Correct 38 ms 10652 KB Output is correct
28 Correct 63 ms 11400 KB Output is correct
29 Correct 37 ms 10700 KB Output is correct
30 Correct 51 ms 11056 KB Output is correct
31 Correct 32 ms 10700 KB Output is correct
32 Correct 37 ms 10704 KB Output is correct
33 Correct 38 ms 10624 KB Output is correct
34 Correct 42 ms 11212 KB Output is correct
35 Correct 50 ms 11212 KB Output is correct
36 Incorrect 34 ms 10976 KB Output isn't correct
37 Halted 0 ms 0 KB -