Submission #496273

# Submission time Handle Problem Language Result Execution time Memory
496273 2021-12-21T04:37:48 Z Ziel Meteors (POI11_met) C++17
0 / 100
6000 ms 10840 KB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");

const int N = 5e5 + 13;
int t[4 * N], u[4 * N];

void push(int x, int lx, int rx) {
	if (u[x]) {
		int mid = (lx + rx) / 2;
		t[2 * x + 1] += u[x] * (mid - lx + 1);
		t[2 * x + 2] += u[x] * (rx - mid + 1);
		u[2 * x + 1] += u[x];
		u[2 * x + 2] += u[x];
		u[x] = 0;
	}
}
void upd(int l, int r, int v, int x, int lx, int rx) {
	if (r < lx || rx < l) return;
	if (l <= lx && rx <= r) {
		t[x] += v * (rx - lx + 1);
		u[x] += v;
		return;
	}
	push(x, lx, rx);
	int mid = (lx + rx) / 2;
	upd(l, r, v, 2 * x + 1, lx, mid);
	upd(l, r, v, 2 * x + 2, mid + 1, rx);
	t[x] = t[2 * x + 1] + t[2 * x + 2];
}
int get(int i, int x, int lx, int rx) {
	if (rx == lx)
		return t[x];
	push(x, lx, rx);
	int mid = (lx + rx) / 2;
	if (i <= mid)
		return get(i, 2 * x + 1, lx, mid);
	else
		return get(i, 2 * x + 2, mid + 1, rx);
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> o(m + 1);
    for (int i = 1; i <= m; i++)
    	cin >> o[i];
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++)
    	cin >> p[i];
    int q;
    cin >> q;
    vector<int> ans(n + 1);
    for (int rep = 1; rep <= q; rep++) {
    	int l, r, x;
    	cin >> l >> r >> x;
    	if (l <= r)
    		upd(l, r, x, 0, 1, m);
    	else {
    		upd(l, m, x, 0, 1, m);
    		upd(1, r, x, 0, 1, m);
       	}
       	vector<int> _p = p;
    	for (int i = 1; i <= m; i++) {
    		p[o[i]] -= get(i, 0, 1, m);
    		if (p[o[i]] <= 0 && !ans[o[i]])
	    		ans[o[i]] = rep;
    	}
    	p = _p;
    }
    for (int i = 1; i <= n; i++) {
    	if (!ans[i])
    		cout << "NIE\n";
    	else
    		cout << ans[i] << '\n';
    }
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

Compilation message

met.cpp: In function 'void setIO(const string&)':
met.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6054 ms 1604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6075 ms 1644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6056 ms 660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6045 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6097 ms 10840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6058 ms 10772 KB Time limit exceeded
2 Halted 0 ms 0 KB -