#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10844 KB |
Output is correct |
2 |
Correct |
3 ms |
10844 KB |
Output is correct |
3 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
10844 KB |
Output is correct |
2 |
Correct |
3 ms |
10844 KB |
Output is correct |
3 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
14800 KB |
Output is correct |
2 |
Correct |
205 ms |
15756 KB |
Output is correct |
3 |
Correct |
169 ms |
15252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
15036 KB |
Output is correct |
2 |
Correct |
170 ms |
15056 KB |
Output is correct |
3 |
Correct |
198 ms |
15704 KB |
Output is correct |
4 |
Correct |
40 ms |
13244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
14964 KB |
Output is correct |
2 |
Correct |
160 ms |
15708 KB |
Output is correct |
3 |
Correct |
102 ms |
13148 KB |
Output is correct |
4 |
Correct |
165 ms |
15404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
14576 KB |
Output is correct |
2 |
Correct |
188 ms |
15080 KB |
Output is correct |
3 |
Correct |
136 ms |
14736 KB |
Output is correct |
4 |
Correct |
201 ms |
16024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1841 ms |
38304 KB |
Output is correct |
2 |
Incorrect |
1767 ms |
32040 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1722 ms |
37924 KB |
Output is correct |
2 |
Incorrect |
1940 ms |
32412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |