이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define INF 100000000000000000
#define INF2 2000000000
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
const int P = 1007;
typedef long long ll;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
const int N = 3e5 + 4;
int arr[N], tar[N], ans[N];
pair<int,int> rang[N];
struct Q
{
int l, r; ll val;
};
Q query[N];
int main()
{
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 1; i <= m; i++) cin >> arr[i];
for(int i = 1; i <= n; i++) {
cin >> tar[i];
ans[i] = -1;
}
int k; cin >> k;
for(int i = 1; i <= k; i++) {
int a, b; ll c;
cin >> a >> b >> c;
query[i].l = a;
query[i].r = b;
query[i].val = c;
}
for(int i = 1; i <= n; i++) {
rang[i].fi = 1;
rang[i].se = k;
}
while(true) {
int mid[k+1] = {};
int where[n+1] = {};
ll cal[n+1] = {};
ll sum[m+2] = {};
bool ok = false;
for(int i = 1; i <= n; i++) {
if(rang[i].fi <= rang[i].se) {
ll indx = (rang[i].fi+rang[i].se)/2;
mid[indx]++;
where[i] = indx;
ok = true;
}
}
if(!ok) break;
for(int i = 1; i <= k; i++) {
int l = query[i].l, r = query[i].r;
ll val = query[i].val;
if(l <= r) {
sum[l] += val;
sum[r+1] -= val;
}
else {
sum[l] += val;
sum[1] += val;
sum[r+1] -= val;
}
if(mid[i] > 0) {
ll cur[m+2] = {};
for(int j = 0; j < m+2; j++) cur[j] = sum[j];
for(int j = 1; j <= m; j++) {
cur[j] += cur[j-1];
if(where[arr[j]] == i) {
cal[arr[j]] += cur[j];
}
}
for(int j = 1; j <= n; j++) {
if(where[j] == i) {
if(cal[j] >= tar[j]) {
ans[j] = i;
rang[j].se = i-1;
}
else {
rang[j].fi = i+1;
}
}
}
}
}
}
for(int i = 1; i <= n; i++) {
if(ans[i] != -1) cout << ans[i] << endl;
else cout << "NIE" << endl;
}
return 0;
}
# | 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... |