#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
using namespace std;
typedef long long int ll;
typedef __int128 lll;
template<typename NodeType,
typename LazyType,
typename F_Merge,
typename F_Update,
typename F_Composition>
struct LazySegTree { // 1-indexed
public:
using A = NodeType;
using B = LazyType;
LazySegTree() : LazySegTree(0, A(), B()) {}
explicit LazySegTree(int n, const A& e, const B& id)
: n(n), e(e), id(id), lg(Log2(n)), sz(1 << lg), tree(sz << 1, e), lazy(sz, id) {}
void Set(int i, const A& val) { tree[--i | sz] = val; }
void Init() { for (int i = sz - 1; i; i--) tree[i] = M(tree[i << 1], tree[i << 1 | 1]); }
void Update(int i, const B& f) {
--i |= sz;
for (int j = lg; j; j--) Push(i >> j);
Apply(i, f);
for (int j = 1; j <= lg; j++) Pull(i >> j);
}
void Update(int l, int r, const B& f) {
--l |= sz, --r |= sz;
for (int i = lg; i; i--) {
if (l >> i << i != l) Push(l >> i);
if (r + 1 >> i << i != r + 1) Push(r >> i);
}
for (int L = l, R = r; L <= R; L >>= 1, R >>= 1) {
if (L & 1) Apply(L++, f);
if (~R & 1) Apply(R--, f);
}
for (int i = 1; i <= lg; i++) {
if (l >> i << i != l) Pull(l >> i);
if (r + 1 >> i << i != r + 1) Pull(r >> i);
}
}
A Query(int i) {
--i |= sz;
for (int j = lg; j; j--) Push(i >> j);
return tree[i];
}
A Query(int l, int r) {
A L = e, R = e; --l |= sz, --r |= sz;
for (int i = lg; i; i--) {
if (l >> i << i != l) Push(l >> i);
if (r + 1 >> i << i != r + 1) Push(r >> i);
}
for (; l <= r; l >>= 1, r >>= 1) {
if (l & 1) L = M(L, tree[l++]);
if (~r & 1) R = M(tree[r--], R);
}
return M(L, R);
}
private:
const int n, lg, sz; const A e; const B id;
vector<A> tree; vector<B> lazy;
F_Merge M; F_Update U; F_Composition C;
static int Log2(int n) {
int ret = 0;
while (n > 1 << ret) ret++;
return ret;
}
void Apply(int i, const B& f) {
tree[i] = U(f, tree[i]);
if (i < sz) lazy[i] = C(f, lazy[i]);
}
void Push(int i) {
Apply(i << 1, lazy[i]);
Apply(i << 1 | 1, lazy[i]);
lazy[i] = id;
}
void Pull(int i) {
tree[i] = M(tree[i << 1], tree[i << 1 | 1]);
}
};
struct NodeType {
lll val; int sz;
constexpr NodeType(lll val, int sz) : val(val), sz(sz) {}
};
constexpr NodeType e(0, 0);
using LazyType = lll;
constexpr LazyType id = 0;
struct F_Merge {
NodeType operator() (const NodeType& a, const NodeType& b) const {
return NodeType(a.val + b.val, a.sz + b.sz);
}
};
struct F_Update {
NodeType operator() (const LazyType& a, const NodeType& b) const {
return NodeType(b.val + a * b.sz, b.sz);
}
};
struct F_Composition {
LazyType operator() (const LazyType& a, const LazyType& b) const {
return a + b;
}
};
LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition> ST(524287, e, id);
ll x,z,w,l,r,m,lazy[1100000];
int le[330000],ri[330000],q,i,j,k,n,s,ee,a[330000];
ll te1,te2,te3;
lll seg[1100000],y;
vector<int> v[330000],u[330000];
pair<pair<int,int>,ll> upd[330000];
void h(ll x,ll y,ll z)
{
if(lazy[z]==0)
return;
if(z>=524288)
{
seg[z]+=lazy[z];
lazy[z]=0;
return;
}
seg[z]+=(y-x+1)*lazy[z];
lazy[z<<1]+=lazy[z];
lazy[(z<<1)+1]+=lazy[z];
lazy[z]=0;
return;
}
void Clear()
{
ll i;
for(i=0;i<1100000;i++)
{
seg[i]=0;
lazy[i]=0;
}
}
void f(ll x,ll y,ll z,ll w)
{
h(x,y,z);
if(l>y||x>r)
return;
if(l<=x&&y<=r)
{
lazy[z]+=w;
h(x,y,z);
return;
}
f(x,(x+y)>>1,z<<1,w);
f(((x+y)>>1)+1,y,(z<<1)+1,w);
seg[z]=seg[z<<1]+seg[(z<<1)+1];
}
lll g(ll x,ll y,ll z)
{
h(x,y,z);
if(l>y||x>r)
return 0;
if(l<=x&&y<=r)
{
return seg[z];
}
return g(x,(x+y)>>1,z<<1)+g(((x+y)>>1)+1,y,(z<<1)+1);
}
int main()
{
scanf("%lld %lld",&te1,&te2);
n=te1;
m=te2;
for(i=1;i<=m;i++)
{
scanf("%lld",&te1);
x=te1;
//x=1;
v[x].push_back(i);
}
for(i=1;i<=n;i++)
{
scanf("%lld",&te1);
a[i]=te1;
//a[i]=1e9;
}
scanf("%lld",&te1);
q=te1;
for(i=1;i<=q;i++)
{
scanf("%lld %lld %lld",&te1,&te2,&te3);
x=te1;
w=te2;
z=te3;
//x=1; w=m; z=1;
upd[i]={{x,w},z};
}
for(i=1;i<=n;i++)
{
le[i]=1;
ri[i]=q+1;
}
for(ee=0;ee<19;ee++)
{
//printf("!");
//for(i=1;i<=n;i++)
// printf("(%lld,%lld)\n",le[i],ri[i]);
Clear();
s=1;
for(i=1;i<=m;i++)
{
ST.Set(i,NodeType(0, 1));
}
ST.Init();
for(i=1;i<=q+1;i++)
{
u[i].clear();
}
for(i=1;i<=n;i++)
u[(le[i]+ri[i])>>1].push_back(i);
for(i=1;i<=q+1;i++)
{
//printf("%lld\n",i);
if(i<=q)
{x=upd[i].first.first;
y=upd[i].first.second;
z=upd[i].second;
if(x<=y)
{
l=x;
r=y;
//f(1,524288,1,z);
ST.Update(l,r,z);
}
else
{
l=x;
r=m;
ST.Update(l,r,z);
l=1;
r=y;
ST.Update(l,r,z);
}
}
//printf("?");
for(j=0;j<u[i].size();j++)
{
x=u[i][j];
y=0;
for(k=0;k<v[x].size();k++)
{
l=v[x][k];
r=v[x][k];
y+=ST.Query(l).val;}
if(a[x]<=y)
{
ri[x]=i;
}
else
le[x]=i+1;
le[x]=min(le[x],q+1);
// printf("[%lld,%lld]\n",(le[x]+ri[x])/2,x);
//p[s]={(le[x]+ri[x])/2,x};
s++;
}
}
//swap(p,pp);
}
for(i=1;i<=n;i++)
{
a[i]=le[i];
}
for(i=1;i<=n;i++)
{
te1=a[i];
if(a[i]>=q+1)
{
printf("NIE\n");
}
else
printf("%lld\n",te1);
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:245:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
245 | for(j=0;j<u[i].size();j++)
| ~^~~~~~~~~~~~
met.cpp:249:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
249 | for(k=0;k<v[x].size();k++)
| ~^~~~~~~~~~~~
met.cpp:258:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
258 | else
| ^~~~
met.cpp:260:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
260 | le[x]=min(le[x],q+1);
| ^~
met.cpp: In instantiation of 'LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition>::LazySegTree(int, const A&, const B&) [with NodeType = NodeType; LazyType = __int128; F_Merge = F_Merge; F_Update = F_Update; F_Composition = F_Composition; LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition>::A = NodeType; LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition>::B = __int128]':
met.cpp:110:83: required from here
met.cpp:60:45: warning: 'LazySegTree<NodeType, __int128, F_Merge, F_Update, F_Composition>::id' will be initialized after [-Wreorder]
60 | const int n, lg, sz; const A e; const B id;
| ^~
met.cpp:60:18: warning: 'const int LazySegTree<NodeType, __int128, F_Merge, F_Update, F_Composition>::lg' [-Wreorder]
60 | const int n, lg, sz; const A e; const B id;
| ^~
met.cpp:17:14: warning: when initialized here [-Wreorder]
17 | explicit LazySegTree(int n, const A& e, const B& id)
| ^~~~~~~~~~~
met.cpp: In instantiation of 'void LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition>::Update(int, int, const B&) [with NodeType = NodeType; LazyType = __int128; F_Merge = F_Merge; F_Update = F_Update; F_Composition = F_Composition; LazySegTree<NodeType, LazyType, F_Merge, F_Update, F_Composition>::B = __int128]':
met.cpp:232:32: required from here
met.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | if (r + 1 >> i << i != r + 1) Push(r >> i);
| ~~^~~
met.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | if (r + 1 >> i << i != r + 1) Pull(r >> i);
| ~~^~~
met.cpp:170:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
170 | scanf("%lld %lld",&te1,&te2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
met.cpp:175:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
175 | scanf("%lld",&te1);
| ~~~~~^~~~~~~~~~~~~
met.cpp:182:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
182 | scanf("%lld",&te1);
| ~~~~~^~~~~~~~~~~~~
met.cpp:186:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
186 | scanf("%lld",&te1);
| ~~~~~^~~~~~~~~~~~~
met.cpp:190:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
190 | scanf("%lld %lld %lld",&te1,&te2,&te3);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
37 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
95 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
61 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |