# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241339 | arnold518 | 단층 (JOI16_ho_t5) | C++14 | 163 ms | 15480 KiB |
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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
struct Data
{
ll X, D, L;
};
int N, Q, S;
Data A[MAXN+10];
struct BIT
{
ll tree[MAXN+10];
void init() { memset(tree, 0, sizeof(tree)); }
void update(int i, ll k) { for(i=max(i, 1); i<=N; i+=(i&-i)) tree[i]+=k; }
ll query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
}bitx, bity;
int main()
{
int i, j;
scanf("%d%d", &N, &Q);
for(i=1; i<=Q; i++) scanf("%lld%lld%lld", &A[i].X, &A[i].D, &A[i].L);
reverse(A+1, A+Q+1);
bitx.init(); bity.init();
bity.update(1, N);
for(i=2; i<=N; i++) bity.update(i, -1);
for(i=1; i<=N; i++) bitx.update(i, 1);
for(i=1; i<=Q; i++)
{
if(A[i].D==1)
{
int lo=0, hi=N+1;
while(lo+1<hi)
{
int mid=lo+hi>>1;
if(bitx.query(mid)<=A[i].X) lo=mid;
else hi=mid;
}
bity.update(N-lo+1, -2*A[i].L);
}
else
{
int lo=0, hi=N+1;
while(lo+1<hi)
{
int mid=lo+hi>>1;
if(bity.query(N-mid+1)>A[i].X) hi=mid;
else lo=mid;
}
bitx.update(hi, 2*A[i].L);
}
//for(j=1; j<=N; j++) printf("(%lld %lld) ", bitx.query(j), bity.query(N-j+1)); printf("\n");
}
for(i=1; i<=N; i++) printf("%lld\n", (bitx.query(i)-bity.query(N-i+1))/2);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |