답안 #716656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716656 2023-03-30T17:22:05 Z Nonoze Addk (eJOI21_addk) C++14
92 / 100
52 ms 7416 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;

#define int ll
#define MN 1e5+5
#define MOD 1000000007
#define endl '\n'
#define endlfl endl << flush
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
const int INF=1e9 + 10;

const auto beg = std::chrono::high_resolution_clock::now();
void dbg_time() {
	auto us = (double)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - beg).count();
	cerr << "Operation time: " << (long double)us/1000000 << " seconds." << endl;
}

int n, k, q;

void solve()
{
	cin >> n >> k;
	vector<int> a(n+1);
	vector<int> P(n+1, 0);
	vector<int> Pmultl(n+1, 0);
	vector<int> Pmultr(n+1, 0);
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		P[i]=P[i-1]+a[i];
		Pmultl[i]=Pmultl[i-1]+a[i]*(n-i+1);
		Pmultr[i]=Pmultr[i-1]+a[i]*i;
	}
	cin >> q;
	while(q--) {
		int action; cin >> action;
		if (action==1) {
			int input; cin >> input;
		} else {
			int l, r, m; cin >> l >> r >> m;
			int sum=(P[r]-P[l-1])*m;
			sum-=(Pmultl[l+m-1]-Pmultl[l-1]) - (P[l+m-1]-P[l-1])*(n-(l+m-1)+1);
			sum-=(Pmultr[r]-Pmultr[r-m+1]) - (P[r]-P[r-m+1])*(r-m+1);
			cout << sum << endl;
		}
	}
	return;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int tt=1;// cin >> tt;
	while(tt--) solve();
	dbg_time();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 700 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 5 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1672 KB Output is correct
2 Correct 20 ms 2404 KB Output is correct
3 Correct 19 ms 3120 KB Output is correct
4 Correct 33 ms 5184 KB Output is correct
5 Correct 45 ms 7416 KB Output is correct
6 Correct 52 ms 7116 KB Output is correct
7 Correct 48 ms 7168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 4052 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -