Submission #633146

# Submission time Handle Problem Language Result Execution time Memory
633146 2022-08-21T16:56:38 Z Jovan26 Addk (eJOI21_addk) C++14
92 / 100
157 ms 6616 KB
#include<bits/stdc++.h>
using namespace std;
long long rez;
int main(){
	#define int long long
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
	long long n;
	cin>>n;
	long long k;
	cin>>k;
	long long  a[n];
	long long pref[n+1];
	for(long i=0;i<n;i++) cin>>a[i];
	long long q;
	pref[0] = 0;
	int preff[n+1];
	preff[0] = 0;
	for(int i=1;i<=n;i++){
		pref[i] = pref[i-1]+a[i-1];
	}
	for(int i=1;i<=n;i++){
		preff[i] = preff[i-1]+pref[i-1];
	}
	//for(int i=0;i<=n;i++) cout<<pref[i]<<" ";
	cin>>q;
	bool p = false;
	for(long long j=0;j<q;j++){
		int x;
		cin>>x;
		if(x==1){
		int y;
		cin>>y;
		 continue;
		}
		long long l,r,m;
		p = true;
		cin>>l>>r>>m;
		long long ma = min(m,(r-l+1-m+1));
		rez = 0;
		l--;
		r--;
	long long z = 0;
	int l1 = l;
	int r1 = l1+ma-2;
	int rez1 =(r1-l1+1)*pref[r1+1]-(preff[r1+1]-preff[l1]);
	int r2 = r;
	int l2 = r2-ma+2;
	int rez2 =-(r2-l2+1)*pref[l2]+(preff[r2+2]-preff[l2+1]);
	int u = (r-l+1)-(r1-l1+1)-(r2-l2+1);
	int rez3 = ma*(pref[l2]-pref[r1+1]);
	rez+=rez1;
	rez+=rez2;
	rez+=rez3;
		cout<<rez<<endl;
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:43:12: warning: unused variable 'z' [-Wunused-variable]
   43 |  long long z = 0;
      |            ^
Main.cpp:50:6: warning: unused variable 'u' [-Wunused-variable]
   50 |  int u = (r-l+1)-(r1-l1+1)-(r2-l2+1);
      |      ^
Main.cpp:27:7: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   27 |  bool p = false;
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 8 ms 592 KB Output is correct
7 Correct 9 ms 596 KB Output is correct
8 Correct 12 ms 724 KB Output is correct
9 Correct 20 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 952 KB Output is correct
2 Correct 49 ms 2120 KB Output is correct
3 Correct 65 ms 2668 KB Output is correct
4 Correct 106 ms 4696 KB Output is correct
5 Correct 157 ms 6616 KB Output is correct
6 Correct 153 ms 6348 KB Output is correct
7 Correct 146 ms 6260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 2172 KB Output isn't correct
2 Halted 0 ms 0 KB -