Submission #964715

#TimeUsernameProblemLanguageResultExecution timeMemory
964715BhavayGoyalMeteors (POI11_met)C++14
74 / 100
1940 ms38304 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define ld long double #define ar array #define vi vector<int> #define vii vector<vector<int>> #define pii pair<int, int> #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define endl "\n" const int MOD = 1e9+7; const int inf = 1e9; const int linf = 1e18; const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // -------------------------------------------------- Main Code -------------------------------------------------- template <class T> struct BIT { int size; vector<T> bit; vector<T> vec; BIT(int n) : size(n), bit(n + 1), vec(n + 1) {} int lsb(int x) { return x & (-x); } void set(int id, T v) { add(id, v - vec[id]); } void add(int id, T v) { if (id == 0) return; vec[id] += v; while (id <= size) { bit[id] += v; id += lsb(id); } } T query(int id) { T tot = 0; if (id == 0) return tot; while (id >= 1) { tot += bit[id]; id -= lsb(id); } return tot; } }; struct state { int l, r; }; const int N = 3e5+5; int req[N], ans[N]; vi positions[N]; void sol() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int x; cin >> x; positions[x].pb(i); } for (int i = 1; i <= n; i++) cin >> req[i]; int q; cin >> q; array<int, 3> queries[q+1]; for (int i = 1; i <= q; i++) { int a, b, c; cin >> a >> b >> c; queries[i] = {a, b, c}; } state currState[n+1]; for (int i = 1; i <= n; i++) currState[i] = {1, q}; for (int temp = 0; temp <= 50; temp++) { vector<int> query[q+1]; for (int i = 1; i <= n; i++) { if (currState[i].l > currState[i].r) continue; query[(currState[i].l+currState[i].r)/2].push_back(i); } BIT<int> tree(m+5); for (int i = 1; i <= q; i++) { int l = queries[i][0], r = queries[i][1], val = queries[i][2]; if (l > r) { swap(l, r); tree.add(r, val); tree.add(1, val); tree.add(l+1, -val); } else { tree.add(l, val); tree.add(r+1, -val); } for (auto j : query[i]) { int ct = 0; for (auto x : positions[j]) { ct += tree.query(x); } int &l = currState[j].l, &r = currState[j].r, mid = (l+r)/2; if (ct >= req[j]) r = mid-1, ans[j] = mid; else l = mid+1; } } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) cout << "NIE" << endl; else cout << ans[i] << endl; } } signed main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { sol(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...