#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set<int> si;
typedef set<ll> sll;
typedef set<char> sch;
typedef long double ld;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a.size())
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define mammad int t; cin >> t; while(t--)
#define int ll
const int maxn = 3e5 + 100;
const int lg = 550;
ll mark[maxn], a[maxn];
ll sum[maxn];
int ans[maxn];
pii cnt[maxn];
bool ok[maxn];
ll ps[maxn], ps2[maxn];
ll c[maxn], L[maxn], R[maxn];;
int n, m, q;
vi ab[maxn];
void up2(int l, int r, int a) // dorost
{
if(l > r)
{
ps2[l] += a;
ps2[m + 1] -= a;
ps2[1] += a;
ps2[r + 1] -= a;
}
else
{
ps2[l] += a;
ps2[r + 1] -= a;
}
}
void upp(int u)
{
for(int i = 1; i <= m; i++)
ps[i] = ps[i - 1] + ps2[i];
for(int i = 1; i <= m; i++)
{
sum[mark[i]] += ps[i];
}
for(int i = 1; i <= m; i++)
ps[i] = ps2[i] = 0;
for(int i = 1; i <= n; i++)
{
if(!ok[i] and sum[i] >= a[i])
{
cnt[i] = {u, sum[i]};
ok[i] = true;
}
}
}
void get(int x)
{
int y = 0;
if(cnt[x].fi == 0)
{
return;
}
int r = min((ll)q, (ll)cnt[x].fi * lg);
int l = 1ll * (cnt[x].fi - 1) * lg;
ll k = cnt[x].se;
for(int i = r; i > l; i--)
{
int g = 0;
for(auto v : ab[x])
{
if(L[i] <= R[i])
{
if(v >= L[i] and v <= R[i])
g++;
}
else
{
if(v <= R[i] or v >= L[i])
g++;
}
}
ll p = 1ll * g * c[i];
if(k - p < a[x])
{
ans[x] = i;
return;
}
k -= p;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
cin >> mark[i];
ab[mark[i]].pb(i);
}
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
cin >> q;
for(int i = 1; i <= q; i++)
{
cin >> L[i] >> R[i] >> c[i];
up2(L[i], R[i], c[i]);
if(i % lg == 0)
upp(i / lg);
}
int p = q / lg;
if(q % lg != 0)
p++;
upp(p);
for(int i = 1; i <= n; i++)
get(i);
for(int i = 1; i <= n; i++)
{
if(ans[i] == 0)
cout << "NIE" << endl;
else
cout << ans[i] << 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... |