#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 + 2, 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 + 2){
fen[k] += x;
k += k&-k;
}
}
struct query{
ll l, r, val;
};
int main(){
cin >> n >> m;
ll p[n];
int o;
vector<vector<ll>> states(n + 1, vector<ll> ());
for (ll i = 0; i < m; i++){
cin >> o;
states[o - 1].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());
for (int i = 0; i <= m + 2; i++)
fen[i] = 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(m + 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:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
64 | for (int i = 0; i <= m + 2; i++)
| ~~^~~~~~~~
met.cpp:81: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]
81 | if (rj[idx] == -1){
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2668 KB |
Output is correct |
2 |
Correct |
5 ms |
2668 KB |
Output is correct |
3 |
Incorrect |
6 ms |
2796 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
5100 KB |
Output is correct |
2 |
Correct |
235 ms |
6588 KB |
Output is correct |
3 |
Incorrect |
180 ms |
5760 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
188 ms |
5352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
5220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
4836 KB |
Output is correct |
2 |
Correct |
176 ms |
5216 KB |
Output is correct |
3 |
Incorrect |
125 ms |
5016 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1739 ms |
23636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1665 ms |
22888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |