This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define REP(i, n) for(int i = 0, _n = n; i < _n; ++i)
#define REPD(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, l, r) for(int i = l, _r = r; i <= _r; ++i)
#define FORD(i, r, l) for(int i = r, _l = l; i >= _l; --i)
#define left __left
#define right __right
#define prev __prev
#define next __next
#define div __div
#define pb push_back
#define pf push_front
#define sz(v) (int)v.size()
#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))
#define debug(v) "[" #v " = " << (v) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b){
a = b;
return true;
}
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b){
a = b;
return true;
}
return false;
}
template<int dimension, class T>
struct vec : public vector<vec<dimension - 1, T>> {
static_assert(dimension > 0, "Dimension must be positive !\n");
template<typename... Args>
vec(int n = 0, Args... args) : vector<vec<dimension - 1, T>>(n, vec<dimension - 1, T>(args...)) {}
};
template<class T>
struct vec<1, T> : public vector<T> {
vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
void init(void);
void process(void);
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#define task "antuvu"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int T = 1; //cin >> T;
while(T--) {
init();
process();
}
return 0;
}
struct FenwickTree{
vector<int64> bit;
FenwickTree(int n) : bit(n + 1, 0) {}
void update(int id, int val){
for(; id < sz(bit); id += id & (-id)){
bit[id] += val;
}
}
int64 query(int id){
int64 sum = 0;
for(; id > 0; id -= id & (-id)){
sum += bit[id];
}
return sum;
}
void update_range(int l, int r, int val){
update(l, val);
update(r + 1, -val);
}
};
const int MAX = 3e5 + 5;
int n, m, k, o[MAX], p[MAX], lq[MAX], rq[MAX], mq[MAX], ansq[MAX], l[MAX], r[MAX], a[MAX];
vector<int> owned_sections[MAX];
void init(){
cin >> n >> m;
REP(i, m){
cin >> o[i];
--o[i];
owned_sections[o[i]].pb(i + 1);
}
REP(i, n){
cin >> p[i];
}
cin >> k;
REP(i, k){
cin >> l[i] >> r[i] >> a[i];
}
}
void parallel_binary_search(){
REP(i, n){
lq[i] = 0, rq[i] = k - 1, ansq[i] = -1;
}
while(true){
vector<int> query_indices;
REP(i, n){
if(lq[i] <= rq[i]){
mq[i] = (lq[i] + rq[i]) >> 1;
query_indices.pb(i);
}
}
if(query_indices.empty()) break;
sort(range(query_indices), [&](int i, int j){
return mq[i] < mq[j];
});
FenwickTree BIT(m);
int j = 0;
REP(i, sz(query_indices)){
int id = query_indices[i];
while(j <= mq[id]){
if(l[j] <= r[j]){
BIT.update_range(l[j], r[j], a[j]);
}
else{
BIT.update_range(1, r[j], a[j]);
BIT.update_range(l[j], m, a[j]);
}
++j;
}
int64 sum = 0;
for(int x : owned_sections[id]){
sum += BIT.query(x);
}
if(sum >= p[id]){
rq[id] = mq[id] - 1;
ansq[id] = mq[id];
}
else lq[id] = mq[id] + 1;
}
}
}
void process(){
parallel_binary_search();
REP(i, n){
if(ansq[i] == -1) cout << "NIE\n";
else cout << ansq[i] + 1 << '\n';
}
}
Compilation message (stderr)
met.cpp: In function 'int main()':
met.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |