이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// main1.cpp
// problem1
//
// Created by Essa Almousa on 2030 / 01/ 01 AD.
//
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
#define pb push_back
#define pF first
#define pS second
#define SP <<" "<<
const ll N = 3e5+10;
struct segment {
vector<ll> tree;
ll offset = 1;
void it(ll n) {
while (offset < n) offset *= 2;
tree.resize(offset*2, 0);
}
void upd(ll v, ll l, ll r, ll ql, ll qr, ll x) {
if (l >= qr || r <= ql) return;
if (l >= ql && r <= qr) {tree[v] += x; return;}
ll mi = (l+r)/2;
upd(v*2, l, mi, ql, qr, x);
upd(v*2+1, mi, r, ql, qr, x);
}
ll query(ll i) {
i--;
i += offset;
ll ans = 0;
while (i >= 1) {
ans += tree[i];
i /= 2;
}
return ans;
}
void upd(ll l, ll r, ll val) {return upd(1, 0, offset, l-1, r, val);}
};
struct query_ {
ll l, r, x;
};
ll a[N], b[N], sol[N];
vector<ll> frq[N];
query_ q[N];
int main() {
//ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
ll n, m;
cin>>n>>m;
for (ll i=1; i<=m; i++) {
cin>>a[i];
frq[a[i]].pb(i);
}
for (ll i=1; i<=n; i++) cin>>b[i];
ll q1;
cin>>q1;
struct binnode { ll i, m, l, r; };
vector<binnode> bin[N];
for (ll i=1; i<=n; i++) {
ll mi = q1+1/2;
bin[mi].pb({i, mi, 1, q1});
}
for (ll i=1; i<=q1; i++) {
ll l, r, x;
cin>>l>>r>>x;
q[i] = {l, r, x};
sol[i] = -1;
}
ll cnt = n;
while (cnt > 0) {
segment tree;
tree.it(m);
for (ll i=1; i<=q1; i++) {
if (q[i].l > q[i].r) {
tree.upd(q[i].l, m, q[i].x);
tree.upd(1, q[i].r, q[i].x);
}
else tree.upd(q[i].l, q[i].r, q[i].x);
for (ll j = bin[i].size()-1; j >= 0; j = bin[i].size()-1) {
binnode& x = bin[i][j];
ll ans = 0; // the num
for (ll k=0; k < frq[x.i].size(); k++) ans += tree.query(frq[x.i][k]);
if (ans >= b[x.i]) x.r = x.m;
else {
if (x.l >= q1) {cnt--;bin[i].pop_back(); continue;};
x.l = x.m+1;
}
ll mid = (x.l+x.r)/2;
if (x.l != x.r) {bin[mid].pb({x.i, mid, x.l, x.r}); cnt++;}
else sol[x.i] = x.l;
bin[i].pop_back();
cnt--;
j = bin[i].size() - 1;
}
}
}
for (ll i=1; i<=n; i++) {
if (sol[i] == -1) cout << "NIE" << endl;
else cout << sol[i] << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
met.cpp: In function 'int main()':
met.cpp:95:32: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (ll k=0; k < frq[x.i].size(); k++) ans += tree.query(frq[x.i][k]);
| ~~^~~~~~~~~~~~~~~~~
# | 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... |