답안 #496600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496600 2021-12-21T15:43:26 Z Ziel Meteors (POI11_met) C++17
24 / 100
6000 ms 21520 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 = "");

string to_string(const string s) {
	return '"' + s + '"';
}
string to_string(const char c) {
 	return char(39) + string(1, c) + char(39);
}
string to_string(const char* s) {
 	return to_string(string(s));
}
string to_string(bool f) {
	return (f ? "true" : "false");
}
template<class A, class B>
string to_string(const pair<A, B> x) {
	return "(" + to_string(x.first) + ", " + to_string(x.second) + ")";
}
template<class A, class B, class C>
string to_string(const tuple<A, B, C> x) {
	return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ")";
}
template<class A, class B, class C, class D>
string to_string(const tuple<A, B, C, D> x) {
	return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ", " + to_string(get<3>(x)) + ")";
}
template<class T>
string to_string(const T v) {
	string res = "{"; bool f = true;
	for (auto x: v)
		res += (f ? to_string(x) : ", " + to_string(x)), f = false;
	return res + "}";
}
void debug_args() { cerr << "]\n"; }
template<class H, class... T>
void debug_args(H x, T... y) {
	cerr << to_string(x);
	if (sizeof... (y))
	cerr << ", ";
	debug_args(y...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: [", debug_args(__VA_ARGS__);
#else
#define debug(...) 47
#endif

const int N = 3e5 + 13;
ll bit[N], prev_bit[N];
int n, m;

void upd(int x, ll v) {
	for (; x <= m + 1; x |= (x + 1))
		bit[x] += v;
}
ll get(int x) {
	ll res = 0;
	for (; x > 0; x = (x & (x + 1)) - 1)
		res += bit[x];
	return res;
}

void prev_upd(int x, ll v) {
	for (; x <= m + 1; x |= (x + 1))
		prev_bit[x] += v;
}
ll prev_get(int x) {
	ll res = 0;
	for (; x > 0; x = (x & (x + 1)) - 1)
		res += prev_bit[x];
	return res;
}

void solve() {
    cin >> n >> m;
    vector<int> o(m + 1);
    vector<vector<int>> occ(n + 1);
    for (int i = 1; i <= m; i++) {
    	cin >> o[i];
    	occ[o[i]].push_back(i);
    }
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++)
    	cin >> p[i];
    
    int q;
    cin >> q;
    int cnt_rep = 0;
    vector<int> l(q + 1), r(q + 1), a(q + 1), ans(n + 1, -1);
    for (int rep = 1; rep <= q; rep++) {
		cin >> l[rep] >> r[rep] >> a[rep];
		if (l[rep] <= r[rep]) {
			upd(l[rep], a[rep]);
			upd(r[rep] + 1, -a[rep]);
		} else {
			upd(l[rep], a[rep]);
			upd(m + 1, -a[rep]);
			upd(1, a[rep]);
			upd(r[rep] + 1, -a[rep]);
		}


    	cnt_rep++;
		if (cnt_rep >= 500) {
			vector<int> cur_p(n + 1);
			for (int i = 1; i <= m; i++)
				cur_p[o[i]] += get(i);
			set<int> temp;
			for (int i = 1; i <= n; i++) {
				if (ans[i] == -1 && cur_p[i] >= p[i])
					temp.insert(i);
			}

			for (int i = rep - 500 + 1; i <= rep; i++) {
				if (l[i] <= r[i]) {
					prev_upd(l[i], a[i]);
					prev_upd(r[i] + 1, -a[i]);
				} else {
					prev_upd(l[i], a[i]);
					prev_upd(m + 1, -a[i]);
					prev_upd(1, a[i]);
					prev_upd(r[i] + 1, -a[i]);
				}
				
				if (sz(temp)) {
					vector<int> del;
					for (int x: temp) {
						int cur = 0;
						debug(occ[x]);
						for (int y: occ[x]) {
							cur += prev_get(y);
						}
						if (cur >= p[x]) {
							ans[x] = i;
							del.push_back(x);
						}
					}
					for (int x: del)
						temp.erase(x);
				}
			}
			cnt_rep = 0;
		}
    }

	{
	    vector<int> cur_p(n + 1);
		for (int i = 1; i <= m; i++)
			cur_p[o[i]] += get(i);
		set<int> temp;
		for (int i = 1; i <= n; i++) {
			if (cur_p[i] >= p[i])
				temp.insert(i);
		}

		for (int i = q - cnt_rep + 1; i <= q; i++) {
			if (l[i] <= r[i]) {
				prev_upd(l[i], a[i]);
				prev_upd(r[i] + 1, -a[i]);
			} else {
				prev_upd(l[i], a[i]);
				prev_upd(m + 1, -a[i]);
				prev_upd(1, a[i]);
				prev_upd(r[i] + 1, -a[i]);
			}
		
			if (sz(temp)) {
				vector<int> del;
				for (int x: temp) {
					int cur = 0;
					for (int y: occ[x]) {
						cur += prev_get(y);
					}
					if (cur >= p[x]) {
						ans[x] = i;
						del.push_back(x);
					}
				}
				for (int x: del)
					temp.erase(x);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		if (ans[i] == -1)
			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 solve()':
met.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 47
      |                    ^~
met.cpp:141:7: note: in expansion of macro 'debug'
  141 |       debug(occ[x]);
      |       ^~~~~
met.cpp: In function 'void setIO(const string&)':
met.cpp:223:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  223 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:224:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  224 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 2368 KB Output is correct
2 Correct 91 ms 3404 KB Output is correct
3 Correct 337 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 282 ms 3024 KB Output is correct
2 Correct 299 ms 3048 KB Output is correct
3 Incorrect 254 ms 4692 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 218 ms 2580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 211 ms 2220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6091 ms 21520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6008 ms 17692 KB Time limit exceeded
2 Halted 0 ms 0 KB -