Submission #942504

# Submission time Handle Problem Language Result Execution time Memory
942504 2024-03-10T18:59:28 Z Clan328 Meteors (POI11_met) C++17
74 / 100
6000 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define nL '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int long long

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const ll MOD = 1e9 + 7;

void settings()__attribute__((constructor));

// void eval(bool condition) { cout << (condition ? "yes" : "no") << nL; }
// void Eval(bool condition) { cout << (condition ? "Yes" : "No") << nL; }
// void EVAL(bool condition) { cout << (condition ? "YES" : "NO") << nL; }

int ipow(int a, int n) {
   if (n == 0) return 1;
   int x = ipow(a, n/2);
   if (n % 2 == 0) return x*x;
   return x*x*a;
}

template <typename T>
ostream& operator<<(ostream& stream, const vector<T>& v) {
	for (auto elem : v) 
		stream << elem << " ";
	return stream;
}

template <typename T>
istream& operator>>(istream& stream, vector<T>& v){
   for(auto &elem : v)
		stream >> elem;
   return stream;
}

void settings() {
	#ifdef LOCAL
		freopen("io/input.txt", "r", stdin);
		freopen("io/output.txt", "w", stdout);
	#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
}

struct Rain {
	int l, r, a;
};

int LOG = 20;

struct SegmentTree {
	vl t, lazy;

	SegmentTree(int n) {
		t = vl(4*n);
		lazy = vl(4*n);
	}

	void push(int v) {
		t[2*v] += lazy[v];
		t[2*v+1] += lazy[v];
		lazy[2*v] += lazy[v];
		lazy[2*v+1] += lazy[v];
		lazy[v] = 0;
	}

	void update(int v, int tl, int tr, int l, int r, int x) {
		if (l > r) return;
		if (l == tl && r == tr) {
			t[v] += x;
			lazy[v] += x;
			return;
		}

		push(v);

		int tm = (tl+tr)/2;
		update(2*v, tl, tm, l, min(r, tm), x);
		update(2*v+1, tm+1, tr, max(tm+1, l), r, x);
		t[v] = max(t[2*v], t[2*v+1]);
	}

	ll get(int v, int tl, int tr, int l, int r) {
		if (l > r) return 0;
		if (l == tl && r == tr) return t[v];

		push(v);

		int tm = (tl+tr)/2;

		return max(get(2*v, tl, tm, l, min(r, tm)), get(2*v+1, tm+1, tr, max(tm+1, l), r));
	}
};

signed main() {
	int n, m;
	cin >> n >> m;
	vi o(m);
	cin >> o;
	for (int i = 0; i < m; i++) o[i]--;
	m *= 2;
	for (int i = m/2; i < m; i++) o.pb(o[i-m/2]);

	vi p(n);
	cin >> p;
	int k;
	cin >> k;
	vector<Rain> lr(k);
	for (int i = 0; i < k; i++) {
		cin >> lr[i].l >> lr[i].r >> lr[i].a;
		lr[i].l--; lr[i].r--;
		if (lr[i].r < lr[i].l) lr[i].r += m/2;
	}

	vvi c(n);
	for (int i = 0; i < m; i++) {
		c[o[i]].pb(i);
	}

	map<pair<int, pii>, vi> b;
	for (int i = 0; i < n; i++) b[{k/2, {0, k-1}}].pb(i);

	vi res(n, -1);
	while (LOG--) {
		SegmentTree tree(m);
		int nxt = 0;
		map<pair<int, pii>, vi> tmp;
		for (auto [key, arr] : b) {
			int l = key.second.first, r = key.second.second, mid = key.first;
			if (l > r) continue;
			for (int i = nxt; i <= mid; i++) {
				tree.update(1, 0, m-1, lr[i].l, lr[i].r, lr[i].a);
				nxt++;
			}
			for (auto u : arr) {
				int sum = 0;
				for (auto v : c[u]) {
					sum += tree.get(1, 0, m-1, v, v);
				}
				// cout << u << " " << l << " " <<r<< nL;
				if (sum < p[u]) tmp[{(mid+1+r)/2, {mid+1, r}}].pb(u);
				else {
					tmp[{(l+mid-1)/2, {l, mid-1}}].pb(u);
					res[u] = mid+1;
				}
			}
		}

		b = tmp;
		tmp.clear();
	}

	for (int i = 0; i < n; i++) {
		if (res[i] != -1) cout << res[i] << nL;
		else cout << "NIE" << nL;
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 600 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 5 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 10288 KB Output is correct
2 Correct 603 ms 11980 KB Output is correct
3 Correct 550 ms 13076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 494 ms 11932 KB Output is correct
2 Correct 509 ms 11860 KB Output is correct
3 Correct 556 ms 12032 KB Output is correct
4 Correct 172 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 11192 KB Output is correct
2 Correct 432 ms 13112 KB Output is correct
3 Correct 65 ms 1872 KB Output is correct
4 Correct 506 ms 13392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 319 ms 10108 KB Output is correct
2 Correct 496 ms 11732 KB Output is correct
3 Correct 445 ms 10336 KB Output is correct
4 Correct 536 ms 14628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 361 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6024 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -