답안 #761649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761649 2023-06-20T06:43:45 Z vjudge1 Meteors (POI11_met) C++17
24 / 100
94 ms 65536 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 5e5+5 , M = 5e7+5, inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;	

int a[N] , b[N] , l[N] , r[N] , c[N] , root[N] , sz , R[M] , L[M];
vector<int> g[N];
ll laz[M];
void push(int v, int ul , int ur) {
	if(laz[v] == 0) return;
	int nvl = sz++;
	laz[nvl] = laz[v]+laz[L[v]];
	L[nvl] = L[L[v]];
	R[nvl] = R[L[v]];
	L[v] = nvl;
	int nvr = sz++;
	laz[nvr] = laz[v]+laz[R[v]];
	L[nvr] = L[R[v]];
	R[nvr] = R[R[v]];
	R[v] = nvr;
	laz[v] = 0;
}
int build(int tl , int tr){
	int nv = sz++;
	if(tl == tr){
		laz[nv] = 0;
		return nv;
	}
	int tm = (tl+tr) >> 1;
	L[nv] = build(tl,tm);
	R[nv] = build(tm+1,tr);
	return nv;
}
int upd(int v, int tl, int tr, int l , int r , int val){
	if(tl > r || tr < l) return v;
	if(l <= tl && tr <= r) {
		int nv = sz++;
		laz[nv] = laz[v] + val;
		L[nv] = L[v];
		R[nv] = R[v];
		return nv;
	}	
	push(v,tl,tr);
	int nv = sz++;
	int tm = (tl + tr) >> 1;
	L[nv] = upd(L[v], tl, tm, l , r , val);
	R[nv] = upd(R[v], tm+1, tr, l , r , val);
	return nv;	
}
int get(int v , int tl , int tr , int pos){
	if(tl == tr) return laz[v];
	int tm = (tl+tr) >> 1;
	push(v,tl,tr);
	if(tm >= pos){
		return get(L[v],tl,tm,pos);
	} else {
		return get(R[v],tm+1,tr,pos);
	}
}
void solve(){
	sz = 1;
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i] , g[a[i]].push_back(i);
	for(int i = 1; i <= n; i++) cin >> b[i];
	int k;
	cin >> k;
	root[0] = build(1,m);
	for(int i = 1; i <= k; i++) {
		cin >> l[i] >> r[i] >> c[i];
		root[i] = root[i-1];
		if(l[i] > r[i]){
			root[i] = upd(root[i],1,m,l[i],m,c[i]);
			root[i] = upd(root[i],1,m,1,r[i],c[i]);
		} else {
			root[i] = upd(root[i],1,m,l[i],r[i],c[i]);	
		}
	}
	int sq = 800;
	for(int i = 1; i <= n; i++){
		if(g[i].size() == 0){
			cout << "NIE\n";
			continue;
		}
		if(g[i].size() <= sq){
			int res = 0;
			for(int l = 1 , r = k; l <= r;){
				int md = (l+r) >> 1;
				ll sum = 0;
				for(int x : g[i]) {
					sum += get(root[md],1,m,x);
				}
				if(sum >= b[i]){
					res = md;
					r = md-1;
				} else {
					l = md+1;
				}
			}
			if(res == 0){
				cout << "NIE\n";
			} else {
				cout << res << "\n";
			}
		} else {
			for(int j = 1; j <= k; j++){
				if(l[j] > r[j]){
					int tl = lower_bound(all(g[i]),l[j])-g[i].begin();
					int tr = upper_bound(all(g[i]),r[j])-g[i].begin();
					int kol = tr + g[i].size()-tl;
					b[i] -= kol*c[j];
				} else{
					int tl = lower_bound(all(g[i]),l[j])-g[i].begin();
					int tr = upper_bound(all(g[i]),r[j])-g[i].begin();
					int kol = max(tr-tl,0);
					b[i] -= kol*c[j];
				}
				if(b[i] <= 0){
					cout << j <<"\n";
					break;
				}
			}		
		}
	}
}
/*

*/
signed main(){
	ios;
	solve();
	return 0;
}

Compilation message

met.cpp: In function 'void solve()':
met.cpp:94:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   94 |   if(g[i].size() <= sq){
      |      ~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13396 KB Output is correct
2 Correct 9 ms 13132 KB Output is correct
3 Correct 8 ms 13780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13012 KB Output is correct
2 Correct 6 ms 13092 KB Output is correct
3 Correct 8 ms 13652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 62 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 85 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 94 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 -