답안 #475446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475446 2021-09-22T13:39:42 Z keta_tsimakuridze Addk (eJOI21_addk) C++14
92 / 100
473 ms 6800 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t, n, q, a[N], tree[4 * N],lazy[4*N];
void push(int u,int l,int r) {
	tree[u] += lazy[u] * (r - l + 1);
	if(l != r) {
		lazy[2 * u] += lazy[u];
		lazy[2 * u + 1] += lazy[u];
	}
	lazy[u] = 0;
}
void upd(int u,int start,int end,int l,int r,int val) {
	push(u,l,r);
	if(l > end || r < start) return;
	if(start <= l && r <= end) {
		lazy[u] = val;
		push(u,l,r);
		return;
	}
	int mid = (l + r)/2;
	upd(2 * u, start, end, l, mid, val);
	upd(2 * u + 1, start, end, mid + 1, r, val);
	tree[u] = tree[2 * u] + tree[2 * u + 1];
}
int get(int u,int start,int end,int l,int r) {
	push(u,l,r);
	if(l > end || r < start) return 0;
	if(start <= l && r <= end) return tree[u];
	int mid = (l + r)/2;
	return get(2 * u, start,end,l,mid) + get(2 * u + 1,start,end,mid+1,r);
}
main(){
	int K;
	cin >> n >> K;
	if(K > 1) return 0;
	for(int i = 1; i <= n; i++) cin >> a[i], upd(1,i,n,1,n,a[i]);
	
	int q;
	cin >> q;
	while(q--) {
		int t;
		cin >> t;
		if(t == 1) {
			int x;
			cin >> x;
			continue;
		}
		int l,r,m;
		cin >> l >> r >> m;
		cout << get(1,l + m - 1, r, 1, n) - get(1,l - 1, r - m, 1,n) << endl;
	}
 }

Compilation message

Main.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 8 ms 332 KB Output is correct
4 Correct 12 ms 460 KB Output is correct
5 Correct 16 ms 508 KB Output is correct
6 Correct 20 ms 644 KB Output is correct
7 Correct 24 ms 656 KB Output is correct
8 Correct 28 ms 672 KB Output is correct
9 Correct 41 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 1768 KB Output is correct
2 Correct 133 ms 2064 KB Output is correct
3 Correct 181 ms 3140 KB Output is correct
4 Correct 320 ms 5944 KB Output is correct
5 Correct 473 ms 6800 KB Output is correct
6 Correct 450 ms 6500 KB Output is correct
7 Correct 439 ms 6468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -