#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 100;
ll f[N];
int L[N], R[N], a[N], p[N], ans[N];
vector <int> on[N];
void upd(int i, int x) {
for (; i < N; i += i & (-i))
f[i] += x;
}
ll get(int i) {
ll s = 0;
for (; i; i -= i & (-i))
s += f[i];
return s;
}
int cur = 0;
void move(int m) {
while (cur != m) {
int x = 0;
if (cur < m) {
cur++;
x = a[cur];
} else {
x = -a[cur];
cur--;
}
if (L[cur] <= R[cur]) {
upd(L[cur], x);
upd(R[cur] + 1, -x);
} else {
upd(L[cur], x);
upd(1, x);
upd(R[cur] + 1, -x);
}
}
}
void dnc(int l, int r, vector <int>& lst) {
if (l > r || lst.empty())
return;
vector <int> win, lose;
int m = (l + r) / 2;
move(m);
for (auto x : lst) {
ll s = 0;
for (auto t : on[x]) {
s += get(t);
if (s >= p[x])
break;
}
if (s >= p[x]) {
ans[x] = m;
win.pb(x);
} else {
lose.pb(x);
}
}
lst.clear();
dnc(l, m - 1, win);
dnc(m + 1, r, lose);
}
ll solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
on[x].pb(i);
}
for (int i = 1; i <= n; i++)
cin >> p[i];
int k;
cin >> k;
for (int i = 1; i <= k; i++) {
cin >> L[i] >> R[i] >> a[i];
}
vector <int> lst;
for (int i = 1; i <= n; i++)
lst.pb(i);
dnc(1, k, lst);
for (int i = 1; i <= n; i++) {
if (ans[i] == 0) {
cout << "NIE\n";
} else {
cout << ans[i] << '\n';
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--) {
solve();
//cout << solve() << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
14940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
14940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
15708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
15600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
47 ms |
15468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
15196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
280 ms |
24588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
291 ms |
23064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |