Submission #865250

# Submission time Handle Problem Language Result Execution time Memory
865250 2023-10-24T06:49:53 Z Nuraly_Serikbay Meteors (POI11_met) C++14
74 / 100
594 ms 65536 KB
//çalışan kazanır//
 
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
#define pb push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
 
const int N = 4e5 + 1;
const int INF = 2e18 + 1;
const int MOD = 1e9 + 7;
const int MODD = 1070234587ll;
const double eps = 0.0001;
//const int p = 87;

int n, m, o[N], p[N], q, l[N], r[N], a[N], ans[N];
pair <int, int> brd[N];
vector <int> pos[N], MID[N];
int t[N*4], mod[N*4];

void push (int v, int tl, int tr) {
	if (mod[v] && tl != tr) {
		mod[v + v] += mod[v], mod[v + v + 1] += mod[v];
		t[v + v] += mod[v], t[v + v + 1] += mod[v];
		mod[v] = 0;
	}
	return;
}

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

int 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 + v, tl, mid, pos);
	return get (v + v + 1, mid + 1, tr, pos);
}

void cl (int v, int tl, int tr) {
	t[v] = mod[v] = 0; 
	if (tl == tr) return;
	int mid = (tl + tr) >> 1;
	cl (v + v, tl, mid), cl (v + v + 1, mid + 1, tr);
	return;
}

void solution () {	
	cin >> n >> m;
	for (int i = 1; i <= m; ++ i) {
		cin >> o[i];
		pos[o[i]].pb (i);
	}
	for (int i = 1; i <= n; ++ i) cin >> p[i];
	cin >> q;
	for (int i = 1; i <= q; ++ i) cin >> l[i] >> r[i] >> a[i];
	for (int i = 1; i <= n; ++ i) brd[i] = make_pair (1, q), ans[i] = -1;
	
	for (int tt = 19; tt >= 0; -- tt) {
		for (int i = 1; i <= n; ++ i) {
			if (brd[i].F > brd[i].S) continue;
			MID[(brd[i].F + brd[i].S) >> 1].pb (i);
		}
		
		for (int mid = 1; mid <= q; ++ mid) {
			if (l[mid] <= r[mid]) upd (1, 1, m, l[mid], r[mid], a[mid]);
			else {
				upd (1, 1, m, 1, r[mid], a[mid]);
				upd (1, 1, m, l[mid], m, a[mid]);
			}
			for (auto i: MID[mid]) {
				int sum = 0;
				for (auto j: pos[i]) sum += get (1, 1, m, j);
				if (sum >= p[i]) brd[i].S = mid - 1, ans[i] = mid;
				else brd[i].F = mid + 1;
			}
		}
		cl (1, 1, m);
		for (int i = 1; i <= q; ++ i) MID[i].clear();
	}	
	for (int i = 1; i <= n; ++ i) {
		if (ans[i] == -1) cout << "NIE\n";
		else cout << ans[i] << '\n';
	}	
	return;
}
 
signed main() {
	YOSIK();
//	srand (time(0));
//	freopen ("E.in", "r", stdin);
//	freopen ("E.out", "w", stdout);
	int TT = 1;// cin >> TT;
	for (int i = 1; i <= TT; ++ i) {
//		cout << "Case " << i << ": ";
		solution ();
		
  	}
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 35164 KB Output is correct
2 Correct 13 ms 35420 KB Output is correct
3 Correct 16 ms 35164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 35672 KB Output is correct
2 Correct 12 ms 35420 KB Output is correct
3 Correct 13 ms 35420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 507 ms 43680 KB Output is correct
2 Correct 587 ms 46868 KB Output is correct
3 Correct 549 ms 47092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 46388 KB Output is correct
2 Correct 539 ms 44968 KB Output is correct
3 Correct 564 ms 48140 KB Output is correct
4 Correct 103 ms 41040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 44132 KB Output is correct
2 Correct 437 ms 47120 KB Output is correct
3 Correct 255 ms 39508 KB Output is correct
4 Correct 535 ms 46384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 543 ms 42964 KB Output is correct
2 Correct 492 ms 46292 KB Output is correct
3 Correct 509 ms 43552 KB Output is correct
4 Correct 567 ms 48304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 594 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -