#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <climits>
#include <vector>
#include <utility>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll> ii;
vector<ll> fen(3e5 + 1, 0);
ll n, m;
ll sum(ll k){
ll s = 0;
while(k > 0){
s += fen[k];
k -= k&-k;
}
return s;
}
void add(ll k, ll x){
while(k <= m){
fen[k] += x;
k += k&-k;
}
}
struct query{
ll l, r, val;
};
int main(){
cin >> n >> m;
ll o[n], p[m];
vector<vector<ll>> states(n + 1, vector<ll> ());
for (ll i = 0; i < m; i++){
cin >> o[i];
o[i]--;
states[o[i]].push_back(i);
}
for (ll i = 0; i < n; i++)
cin >> p[i];
ll k;
cin >> k;
vector<query> q; query Q;
for (ll i = 0; i < k; i++){
cin >> Q.l >> Q.r >> Q.val;
Q.l--; Q.r--;
q.push_back(Q);
}
vector<ll> lo(n, 0), hi(n, k), rj(n, -1);
ll cnt = 0;
while(cnt < n){
vector<ii> mid(n);
for (ll i = 0; i < n; i++)
mid[i] = {(lo[i] + hi[i])/2, i};
sort(mid.begin(), mid.end());
fen.assign(n + 1, 0);
ll j = 0;
for (ll i = 0; i < k; i++){
if (q[i].l < q[i].r){
add(q[i].l + 1, q[i].val);
add(q[i].r + 2, -q[i].val);
}
else{
add(q[i].l + 1, q[i].val);
add(1, q[i].val);
add(q[i].r + 2, -q[i].val);
}
while(j < n && mid[j].first == i){
ll idx = mid[j].second;
if (rj[idx] == -1){
ll suma = 0;
for (ll l = 0; l < states[idx].size(); l++){
suma += sum(states[idx][l] + 1);
if (suma >= p[idx])
break;
}
if (suma >= p[idx])
hi[idx] = i;
else
lo[idx] = i + 1;
if (lo[idx] >= hi[idx]){
cnt++;
rj[idx] = lo[idx];
}
}
j++;
}
}
}
for (ll i = 0; i < n; i++){
if (rj[i] == k)
cout << "NIE" << endl;
else
cout << rj[i] + 1 << endl;
}
return 0;
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:79:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
79 | if (rj[idx] == -1){
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
5228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
5740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6124 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
5740 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
5228 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
16620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
54 ms |
15084 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |