105742024-04-05 19:51:49999Branch Cuttingcpp17Time limit exceeded 43/1002.099s4840 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int mod(int num, int m){
	if(num>=0)return num%m;
	else{
		return (num+m)%m;
		//num az min -1 tehat eleg 1db +m
	}
}

int main() {
	int n,q;cin>>n>>q;
	vector<int> v(n);
	int mindex=0;
	for(int i = 0;i<n;i++){
			cin>>v[i];
	}
	for(int i = 0;i<=q;i++){
		if(i!=0){
			int a=0,b=0;	
			cin>>a>>b;
			v[a]=b;
		}
		for(int i = 0;i<n;i++){
			if(v[i]<v[mindex]||(v[i]==v[mindex]&&(i==n-1&&v[0]!=v[mindex]||v[i]!=v[i+1]))){
				mindex=i;
			}
		}
		int ans=0;
		int j=(mindex+1)%n;
		while(j!=mindex){
			if(j==(mindex+1)%n&&ans>0)break;
			if(v[mod(j-1,n)]<v[j]){
				ans++;
				j++;
			}
			j++;
			j%=n;
		}
		cout<<ans<<' ';
	}
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2004 KiB
subtask28/8
3Accepted3ms2212 KiB
4Accepted3ms2464 KiB
5Accepted3ms2660 KiB
6Accepted3ms2888 KiB
7Accepted3ms2808 KiB
8Accepted3ms2948 KiB
9Accepted3ms3148 KiB
10Accepted3ms3388 KiB
11Accepted3ms3356 KiB
subtask30/15
12Time limit exceeded2.099s3536 KiB
13Time limit exceeded2.065s3484 KiB
14Time limit exceeded2.062s3560 KiB
15Time limit exceeded2.046s3520 KiB
16Time limit exceeded2.065s3352 KiB
17Time limit exceeded2.058s3556 KiB
18Time limit exceeded2.062s3640 KiB
subtask410/10
19Accepted3ms3564 KiB
20Accepted3ms3588 KiB
21Accepted17ms3484 KiB
22Accepted17ms3480 KiB
23Accepted17ms3604 KiB
24Accepted16ms3480 KiB
25Accepted17ms3584 KiB
26Accepted17ms3588 KiB
subtask525/25
27Accepted6ms3504 KiB
28Accepted4ms3508 KiB
29Accepted830ms3508 KiB
30Accepted938ms3588 KiB
31Accepted894ms3592 KiB
32Accepted675ms3592 KiB
33Accepted676ms3592 KiB
34Accepted917ms3512 KiB
subtask60/42
35Accepted92ms4836 KiB
36Accepted39ms4840 KiB
37Time limit exceeded2.069s3536 KiB
38Time limit exceeded2.059s3696 KiB
39Time limit exceeded2.051s3840 KiB
40Time limit exceeded2.065s3688 KiB
41Time limit exceeded2.073s3744 KiB
42Time limit exceeded2.078s3964 KiB
43Time limit exceeded2.051s4024 KiB