結果
| 問題 |
No.255 Splarrraaay スプラーレェーーイ
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-11-20 18:42:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,005 bytes |
| コンパイル時間 | 2,534 ms |
| コンパイル使用メモリ | 235,992 KB |
| 最終ジャッジ日時 | 2025-01-06 16:56:36 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:100:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
100 | scanf("%lld %lld",&n,&q);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:104:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
104 | scanf("%lld %lld %lld",&xs[i],&ls[i],&rs[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template <typename T,typename E>
struct SegmentTree{
using F = function<T(T,T)>;
using G = function<T(T,E)>;
using H = function<E(E,E)>;
Int n,height;
F f;
G g;
H h;
T ti;
E ei;
vector<T> dat;
vector<E> laz;
SegmentTree(F f,G g,H h,T ti,E ei):
f(f),g(g),h(h),ti(ti),ei(ei){}
void init(Int n_){
n=1;height=0;
while(n<n_) n<<=1,height++;
dat.assign(2*n,ti);
laz.assign(2*n,ei);
}
void build(const vector<T> &v){
Int n_=v.size();
init(n_);
for(Int i=0;i<n_;i++) dat[n+i]=v[i];
for(Int i=n-1;i;i--)
dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
inline T reflect(Int k){
return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
}
inline void eval(Int k){
if(laz[k]==ei) return;
laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
dat[k]=reflect(k);
laz[k]=ei;
}
inline void thrust(Int k){
for(Int i=height;i;i--) eval(k>>i);
}
inline void recalc(Int k){
while(k>>=1)
dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
}
void update(Int a,Int b,E x){
thrust(a+=n);
thrust(b+=n-1);
for(Int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) laz[l]=h(laz[l],x),l++;
if(r&1) --r,laz[r]=h(laz[r],x);
}
recalc(a);
recalc(b);
}
void set_val(Int a,T x){
thrust(a+=n);
dat[a]=x;laz[a]=ei;
recalc(a);
}
T query(Int a,Int b){
thrust(a+=n);
thrust(b+=n-1);
T vl=ti,vr=ti;
for(Int l=a,r=b+1;l<r;l>>=1,r>>=1) {
if(l&1) vl=f(vl,reflect(l++));
if(r&1) vr=f(reflect(--r),vr);
}
return f(vl,vr);
}
};
template<typename T>
vector<T> compress(vector<T> v){
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
return v;
}
template<typename T>
map<T, Int> dict(const vector<T> &v){
map<T, Int> res;
for(Int i=0;i<(Int)v.size();i++)
res[v[i]]=i;
return res;
}
//INSERT ABOVE HERE
signed main(){
Int n,q;
scanf("%lld %lld",&n,&q);
vector<Int> xs(q),ls(q),rs(q);
for(Int i=0;i<q;i++)
scanf("%lld %lld %lld",&xs[i],&ls[i],&rs[i]);
vector<Int> vs({0,n});
for(Int i=0;i<q;i++){
vs.emplace_back(ls[i]);
vs.emplace_back(++rs[i]);
}
vs=compress(vs);
auto dc=dict(vs);
using T = tuple<Int, Int, Int, Int, Int, Int>;
using E = tuple<Int, Int, Int>;
const Int MOD = Int(1e18)+Int(9);
auto add=[&](Int a,Int b){a+=b;return a>=MOD?a-MOD:a;};
auto mul=[&](Int a,Int b){
Int r=0;
while(b){
if(b&1) r=add(r,a);
a=add(a,a);
b>>=1;
}
return r;
};
T ti(0,0,0,0,0,0);
E ei(1,0,0);
auto f=[&](T x,T y){
Int xa,xb,xc,xd,xe,xs;
tie(xa,xb,xc,xd,xe,xs)=x;
Int ya,yb,yc,yd,ye,ys;
tie(ya,yb,yc,yd,ye,ys)=y;
return T(add(xa,ya),add(xb,yb),add(xc,yc),
add(xd,yd),add(xe,ye),add(xs,ys));
};
auto g=[&](T x,E y){
assert(y!=ei);
Int xa,xb,xc,xd,xe,xs;
tie(xa,xb,xc,xd,xe,xs)=x;
Int yf,yt,ys;
tie(yf,yt,ys)=y;
assert(yt!=0&&ys!=0);
if(yt==0) return x;
Int v=mul(xs,ys);
yf=0;
if(yt==1) return T(add(yf*xa,v),0,0,0,0,xs);
if(yt==2) return T(0,add(yf*xb,v),0,0,0,xs);
if(yt==3) return T(0,0,add(yf*xc,v),0,0,xs);
if(yt==4) return T(0,0,0,add(yf*xd,v),0,xs);
if(yt==5) return T(0,0,0,0,add(yf*xe,v),xs);
assert(0);
return x;
};
auto h=[&](E x,E y){
assert(y!=ei);
if(x==ei) return y;
Int xf,xt,xs;
tie(xf,xt,xs)=x;
Int yf,yt,ys;
tie(yf,yt,ys)=y;
assert(yt!=0&&ys!=0);
return E(xf&&yf&&(xt==yt),yt,add((xt==yt)*xs,ys));
};
SegmentTree<T, E> seg(f,g,h,ti,ei);
vector<T> vt;
for(Int i=0;i+1<(Int)vs.size();i++)
vt.emplace_back(0,0,0,0,0,vs[i+1]-vs[i]);
seg.build(vt);
Int sa=0,sb=0,sc=0,sd=0,se=0;
for(Int i=0;i<q;i++){
Int x=xs[i],l=dc[ls[i]],r=dc[rs[i]];
assert(vs[l]==ls[i]);
assert(vs[r]==rs[i]);
if(x==0){
Int a,b,c,d,e,s;
tie(a,b,c,d,e,s)=seg.query(l,r);
map<Int, Int> m;
m[a]++;m[b]++;m[c]++;m[d]++;m[e]++;
Int v=(--m.end())->first;
if(m[v]!=1) continue;
if(a==v) sa=add(sa,v);
if(b==v) sb=add(sb,v);
if(c==v) sc=add(sc,v);
if(d==v) sd=add(sd,v);
if(e==v) se=add(se,v);
}
if(x) seg.update(l,r,E(1,x,1));
}
Int a,b,c,d,e,s;
tie(a,b,c,d,e,s)=seg.query(0,dc[n]);
sa=add(sa,a);
sb=add(sb,b);
sc=add(sc,c);
sd=add(sd,d);
se=add(se,e);
printf("%lld %lld %lld %lld %lld\n",sa,sb,sc,sd,se);
return 0;
}
beet