Submission #68345262
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> ppl;
typedef pair<ll,ppl> pppl;
typedef pair<ll,pppl> pppppl;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) begin(a),end(a)
#define sz(a) (int)(a).size()
#define F first
#define S second
#define bs(A,x) binary_search(all(A),x)
#define lb(A,x) (ll)(lower_bound(all(A),x)-A.begin())
#define ub(A,x) (ll)(upper_bound(all(A),x)-A.begin())
#define cou(A,x) (ll)(upper_bound(all(A),x)-lower_bound(all(A),x))
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
//*
using mint=modint998244353;
const ll mod=998244353;
//*/
/*
using mint=modint1000000007;
const ll mod=1000000007;
//*/
//using mint=modint;
//*
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;
typedef vector<vvvm> vvvvm;
ostream&operator<<(ostream&os,mint a){os<<a.val();return os;}
istream&operator>>(istream&is,mint&a){int x;is>>x;a=mint(x);return is;}
//*/
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>v){rep(i,0,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
struct S{
mint a,b,c,d;
bool operator==(S x){
return x.a==a&&x.b==b&&x.c==c&&x.d==d;
}
//00,01,10,11
};
S e(){
return S{12749234,1249703214,57333387932,414315970};
}
S op(S x,S y){
if(x==e())return y;
if(y==e())return x;
return S{x.a*(y.a+y.c)+x.b*y.a,x.a*(y.b+y.d)+x.b*y.b,x.c*(y.a+y.c)+x.d*y.a,x.c*(y.b+y.d)+x.d*y.b};
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll N,Q;cin>>N>>Q;
vl A(N+1,-1);
A[0]=0;
segtree<S,op,e>seg(N+1);
vm F(N+10,1);
rep(i,2,N+10)F[i]=F[i-1]+F[i-2];
vm ex(2e6,1),re(2e6);
rep(i,1,2e6)ex[i]=i*ex[i-1];
rep(i,0,2e6)re[i]=1/ex[i];
set<ll>st={0};
auto f=[&](ll i){
auto it=st.upper_bound(i);
if(it==st.end()){
if(i==N-1)seg.set(i,S{1,0,0,1});
else seg.set(i,S{F[N-i-1],F[N-i-2],F[N-i-2],(N-i-3>=0?F[N-i-3]:0)});
}
else{
ll j=*it;
if(j==i+1){
if(A[i]==A[j])seg.set(i,S{1,0,0,0});
else if(A[j]==A[i]+1)seg.set(i,S{0,0,0,1});
else seg.set(i,S{0,0,0,0});
}
else if(j==i+2){
if(A[i]==A[j])seg.set(i,S{1,0,0,0});
else if(A[j]==A[i]+1)seg.set(i,S{0,1,1,0});
else seg.set(i,S{0,0,0,0});
}
else{
ll a=A[j]-A[i],d=j-i;
mint x=0,y=0,z=0,w=0;
if(d-1-2*a>=0&&a>=0)x=ex[d-a-1]*re[a]*re[d-2*a-1];
if(a>=1&&d-2*a>=0)y=z=ex[d-a-1]*re[a-1]*re[d-2*a];
if(a>=2&&d-2*a+1>=0)w=ex[d-a-1]*re[a-2]*re[d-2*a+1];
seg.set(i,S{x,y,z,w});
}
}
};
f(0);
while(Q--){
ll x,y;cin>>x>>y;
if(y!=-1){
st.insert(x);
auto it=st.find(x);
A[x]=y;
f(x);f(*prev(it));
if(it!=prev(st.end()))f(*next(it));
}
else if(A[x]!=-1){
st.erase(x);
seg.set(x,e());
auto it=st.lower_bound(x);
A[x]=y;
if(it!=st.end())f(*it);
f(*prev(it));
}
auto s=seg.prod(0,N);
cout<<(s.a+s.b+s.c+s.d)<<endl;
// cout<<"!"<<endl;
// rep(i,0,N+1)cout<<seg.get(i).a<<","<<seg.get(i).b<<","<<seg.get(i).c<<","<<seg.get(i).d<<endl;
// cout<<endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - We're teapots |
User |
TKTYI |
Language |
C++ 20 (gcc 12.2) |
Score |
550 |
Code Size |
4124 Byte |
Status |
AC |
Exec Time |
738 ms |
Memory |
32892 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
550 / 550 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-sample-01.txt |
All |
00-sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-01.txt |
AC |
210 ms |
18716 KiB |
01-01.txt |
AC |
254 ms |
18652 KiB |
01-02.txt |
AC |
257 ms |
18816 KiB |
01-03.txt |
AC |
223 ms |
18652 KiB |
01-04.txt |
AC |
561 ms |
28860 KiB |
01-05.txt |
AC |
561 ms |
29368 KiB |
01-06.txt |
AC |
560 ms |
29340 KiB |
01-07.txt |
AC |
562 ms |
29348 KiB |
01-08.txt |
AC |
716 ms |
27100 KiB |
01-09.txt |
AC |
738 ms |
32860 KiB |
01-10.txt |
AC |
730 ms |
32828 KiB |
01-11.txt |
AC |
637 ms |
32832 KiB |
01-12.txt |
AC |
636 ms |
32892 KiB |
01-13.txt |
AC |
587 ms |
28836 KiB |
01-14.txt |
AC |
598 ms |
24392 KiB |
01-15.txt |
AC |
585 ms |
29336 KiB |
01-16.txt |
AC |
591 ms |
29468 KiB |