답안 #865721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865721 2023-10-24T14:43:40 Z vjudge1 Meteors (POI11_met) C++17
74 / 100
4536 ms 65536 KB
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int long long

#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"

const int maxn = (int)3e5 + 13;
const ll inf = (long long)1e18 + 20;
const int mod = (int)1e9 + 7;

int n,m;
vector<int>pos[maxn],MID[maxn];
int a[maxn];
int l[maxn],r[maxn],w[maxn];
pair<int,int>seg[maxn];
ll t[maxn * 4],q[maxn * 4];

void push(int v,int tl,int tr){
	if(q[v]){
		t[v] += q[v] * (tr - tl + 1);
		if(tl < tr){
			q[v * 2] += q[v];
			q[v * 2 + 1] += q[v];
		}
		q[v] = 0;
	}
}

void upd(int v,int tl,int tr,int l,int r,int x){
	push(v,tl,tr);
	if(l <= tl && tr <= r){
		q[v] += x;
		push(v,tl,tr);
		return;
	}
	int mid = (tl + tr) >> 1;
	if(l > tr || r < tl)return;
	upd(v * 2,tl,mid,l,r,x);
	upd(v * 2 + 1,mid + 1,tr,l,r,x);
	t[v] = t[v * 2] + t[v * 2 + 1];
}

ll get(int v,int tl,int tr,int pos){
	push(v,tl,tr);
	if(tl == tr){
		return t[v];
	}
	int mid = (tl + tr) >> 1;
	if(pos <= mid){
		return get(v * 2,tl,mid,pos);
	}
	else{
		return get(v * 2 + 1,mid + 1,tr,pos);
	}
}

void build(int v,int tl,int tr){
	if(tl == tr){
		t[v] = 0;
		q[v] = 0;
		return;
	}
	int mid = (tl + tr) >> 1;
	build(v * 2,tl,mid);
	build(v * 2 + 1,mid + 1,tr);
	t[v] = 0,q[v] = 0;
}

ll ans[maxn];

void solve(){
	cin >> n >> m;
	for(int i = 1 ; i <= m ; i ++){
		int o;cin >> o;
		pos[o].pb(i);
	}
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
	}
	int k;cin >> k;
	for(int i = 1 ; i <= k ; i++){
		cin >> l[i] >> r[i] >> w[i];
	}
	for(int i = 1 ; i <= n ; i ++){
		seg[i] = {1,k + 1};
	}
	int lg = 19;
	while(lg --){
		build(1,1,m);
		for(int i = 1 ; i <= n ; i ++){
			if(seg[i].first <= seg[i].second){
				int mid = (seg[i].first + seg[i].second) >> 1;
				MID[mid].pb(i);
			}
		}
		for(int i = 1 ; i <= k ; i ++){
			if(l[i] <= r[i]){
				upd(1,1,m,l[i],r[i],w[i]);
			}
			else{
				upd(1,1,m,l[i],m,w[i]);
				upd(1,1,m,1,r[i],w[i]);
			}
			ll sum = 0;
			for(int x : MID[i]){
				sum = 0;
				for(int y : pos[x]){
					sum += get(1,1,m,y);
					if(sum >= a[x])break;
				}
				if(sum >= a[x]){
					seg[x].second = i ;
					if(!ans[x])ans[x] = i;
				}
				else{
					seg[x].first = i + 1;
				}
			}
			MID[i].clear();
		}
	}
	for(int i = 1 ; i <= n ; i ++){
		if (seg[i].first == k + 1) cout << "NIE\n";
		else cout << seg[i].first << '\n';
	}
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t --){
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 25944 KB Output is correct
2 Correct 11 ms 26200 KB Output is correct
3 Correct 12 ms 25948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 25948 KB Output is correct
2 Correct 11 ms 26176 KB Output is correct
3 Correct 12 ms 26204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 28964 KB Output is correct
2 Correct 566 ms 31116 KB Output is correct
3 Correct 562 ms 30368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 29780 KB Output is correct
2 Correct 562 ms 30168 KB Output is correct
3 Correct 554 ms 31060 KB Output is correct
4 Correct 102 ms 30160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 29416 KB Output is correct
2 Correct 452 ms 31920 KB Output is correct
3 Correct 259 ms 26244 KB Output is correct
4 Correct 545 ms 30936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 534 ms 28512 KB Output is correct
2 Correct 479 ms 30036 KB Output is correct
3 Correct 515 ms 28804 KB Output is correct
4 Correct 580 ms 32460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4492 ms 53672 KB Output is correct
2 Correct 2578 ms 45664 KB Output is correct
3 Correct 1280 ms 27732 KB Output is correct
4 Runtime error 4479 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4536 ms 52560 KB Output is correct
2 Correct 1347 ms 45268 KB Output is correct
3 Correct 1031 ms 28192 KB Output is correct
4 Runtime error 3527 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -