답안 #855911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855911 2023-10-02T08:55:33 Z Nuraly_Serikbay Meteors (POI11_met) C++17
24 / 100
389 ms 65536 KB
#include "bits/stdc++.h"
  
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1  
#define int long long
  
using namespace std;
 
/*
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
	#pragma GCC optimize("unroll-loops")
*/
 
typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double D;
typedef long double lld;
   
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const ll INF = 1e18 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const D eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;   
 
int n, m;
int a[N], t[N * 4], L[N], R[N], x[N], sum[N];
vector <int> v[N], MID[N];
pair <int, int> p[N];
 
void push (int v, int l, int r) {
	if (t[v] != 0 && l != r) {
		t[v * 2] += t[v];
		t[v * 2 + 1] += t[v];
		t[v] = 0;	
	}
	return;
}
 
void update (int v, int l, int r, int L, int R, int val) {	
	if (R < l || r < L) return;
	if (L <= l && r <= R) {
		t[v] += val;
		push(v, l, r);	
		return;
	}
	push(v, l, r);
	int mid = (l + r) / 2;
	update (v * 2, l, mid, L, R, val);
	update (v * 2 + 1, mid + 1, r, L, R, val);
	return;
}
 
int get (int v, int l, int r, int pos) {
	if (l == r) {	
		return t[v];
	}
	push(v, l, r);
	int mid = (l + r) / 2;
	if (pos <= mid) return get (v * 2, l, mid, pos);
	else return get (v * 2 + 1, mid + 1, r, pos);
}
 
 
int check (int w, int pos) {	
	for (int i = 1; i <= w; ++i) {
		if (L[i] > R[i]) {
			update(1, 1, m, L[i], m, x[i]);
			update(1, 1, m, 1, R[i], x[i]);
		} else {
			update(1, 1, m, L[i], R[i], x[i]);
		}
	}
	int ans = 0; 
	for (auto to : v[pos]) {
		ans += get(1, 1, m, to);	
	}
	for (int i = 1; i <= m * 4; ++i) t[i] = 0;
	return ans;
 
}
 
void Solution (/*Nuraly.Serikbay*/) {
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		cin >> sum[i];
		v[sum[i]].pb(i);	
	}
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];	
	}
	int q;
	cin >> q;
	for (int i = 1; i <= q; ++i) {
		cin >> L[i] >> R[i] >> x[i];		 
	}
	for (int i = 1; i <= n; ++ i) {
		p[i] = mp (0, q + 1);
	}
	for (int tt = 1; tt <= 18; ++ tt) {
		for (int i = 1; i <= n; ++ i) {
			if (p[i].F >= p[i].S) continue;
			MID[(p[i].F + p[i].S) >> 1].pb (i);
		}
		for (int mid = 1; mid <= q; ++ mid) {
			if (L[mid] > R[mid]) {
				update (1, 1, m, L[mid], m, x[mid]);
				update (1, 1, m, 1, R[mid], x[mid]);
			} else {
				update (1, 1, m, L[mid], R[mid], x[mid]);
			}
		
			for (auto to: MID[mid]) {
				ll ans = 0;
				for (auto u: v[to]) {
					ans += get (1, 1, m, u);
				}
				if (ans >= a[to]) p[to].S = mid;
				else p[to].F = mid;
			}
		}
		for (int i = 1; i <= m * 4; ++ i) t[i] = 0;
		for (int i = 1; i <= q; ++ i) MID[i].clear();
	}
	for (int i = 1; i <= n; ++ i) {
			if (p[i].S == q + 1) cout << "NIE\n";
			else cout << p[i].S << '\n';
	}
}
signed main () {
	YOSIK();
	ll T = 1;
	//cin >> T;
	while (T --) {
		Solution ();
	}
	exit (0);
}/*
 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 58008 KB Output is correct
2 Correct 16 ms 57948 KB Output is correct
3 Correct 17 ms 58000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 57944 KB Output is correct
2 Correct 16 ms 57944 KB Output is correct
3 Correct 17 ms 57948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 64848 KB Output is correct
2 Runtime error 90 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 65536 KB Output is correct
2 Correct 389 ms 65536 KB Output is correct
3 Runtime error 91 ms 65536 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 65256 KB Output is correct
2 Runtime error 64 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 64236 KB Output is correct
2 Correct 351 ms 65536 KB Output is correct
3 Correct 353 ms 64592 KB Output is correct
4 Runtime error 84 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 92 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 91 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -