QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246445 | #6672. Colorful Segments | yiyiyi | AC ✓ | 416ms | 36548kb | C++20 | 4.1kb | 2023-11-10 20:27:40 | 2023-11-10 20:27:42 |
Judging History
answer
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<bitset>
#include<set>
#define int long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define forE(i,x) for(int i=head[x];i;i=nxt[i])
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=4e5+5;
const int mod=998244353;
const int INF=1e9;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+(c-'0');
c=getchar();
}
return x*f;
}
struct SegTree{
struct node{
int l,r;
long long pre,add,mul;
}t[maxn<<2];
inline void spread(int p)
{
if(t[p].mul!=1)
{
t[p*2].add*=t[p].mul,t[p*2].mul*=t[p].mul;
t[p*2+1].add*=t[p].mul,t[p*2+1].mul*=t[p].mul;
t[p*2].pre*=t[p].mul,t[p*2+1].pre*=t[p].mul;
t[p*2].add%=mod;t[p*2].mul%=mod;t[p*2].pre%=mod;
t[p*2+1].add%=mod;t[p*2+1].mul%=mod;t[p*2+1].pre%=mod;
t[p].mul=1;
}
if(t[p].add)
{
t[p*2].add+=t[p].add;t[p*2+1].add+=t[p].add;
t[p*2].pre+=(t[p*2].r-t[p*2].l+1)*t[p].add%mod;
t[p*2+1].pre+=(t[p*2+1].r-t[p*2+1].l+1)*t[p].add%mod;
t[p*2].add%=mod;t[p*2].pre%=mod;
t[p*2+1].add%=mod;t[p*2+1].pre%=mod;
t[p].add=0;
}
}
inline void pushup(int p)
{
t[p].pre=(t[p*2].pre+t[p*2+1].pre)%mod;
}
inline void build(int p,int l,int r)
{
t[p].l=l;t[p].r=r;t[p].add=0,t[p].mul=1;
if(l==r)
{
t[p].pre=0;
return;
}
int mid=(t[p].l+t[p].r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
pushup(p);
}
inline void change(int p,int l,int r,int v)
{
if(t[p].l>=l&&t[p].r<=r)
{
t[p].pre+=(t[p].r-t[p].l+1)*v%mod;t[p].add+=v;
t[p].add%=mod;t[p].pre%=mod;
return;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
if(l<=mid) change(p*2,l,r,v);
if(r>mid) change(p*2+1,l,r,v);
pushup(p);
}
inline void changemul(int p,int l,int r,int v)
{
if(t[p].l>=l&&t[p].r<=r)
{
t[p].pre*=v;t[p].mul*=v;t[p].add*=v;
t[p].pre%=mod;t[p].mul%=mod;t[p].add%=mod;
return;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
if(l<=mid) changemul(p*2,l,r,v);
if(r>mid) changemul(p*2+1,l,r,v);
pushup(p);
}
inline int ask(int p,int l,int r)
{
if(t[p].l>=l&&t[p].r<=r)
{
return t[p].pre%mod;
}
spread(p);
int mid=(t[p].l+t[p].r)/2;
int res=0;
if(l<=mid) res+=ask(p*2,l,r);
res%=mod;
if(r>mid) res+=ask(p*2+1,l,r);
return res%mod;
}
}S[2];
int T;
struct node{
int l,r,col;
}a[maxn];
int f[maxn];
int c[maxn];
signed main()
{
int T=read();
while(T--)
{
int n=read(),tot=0;
rep(i,1,n) a[i]={read(),read(),read()};
// rep(i,1,n) c[++tot]=a[i].l,c[++tot]=a[i].r;
// sort(c+1,c+tot+1);
// int len=unique(c+1,c+tot+1)-c-1;
a[++n]={0,0,1};a[++n]={0,0,0};
// rep(i,1,n) a[i].l=lower_bound(c+1,c+len+1,a[i].l)-c,a[i].r=lower_bound(c+1,c+len+1,a[i].r)-c;
sort(a+1,a+n+1,[&](node u,node v)-> bool {return u.r<v.r;});
// rep(i,1,n)
// {
// printf("%lld %lld %lld\n",a[i].l,a[i].r,a[i].col);
// }
int ans=0;
S[0].build(1,1,n);S[1].build(1,1,n);
S[0].change(1,1,1,1);S[1].change(1,2,2,1);
rep(i,3,n)
{
int l=a[i].l,r=a[i].r,col=a[i].col;
int L=1,R=i,res=-1;
while(L<=R)
{
int mid=(L+R)/2;
if(a[mid].r<a[i].l) res=mid,L=mid+1;
else R=mid-1;
}
f[i]=0;
f[i]+=(S[col^1].ask(1,1,res))%mod;f[i]%=mod;
S[col^1].changemul(1,1,res,2);
S[col].change(1,i,i,f[i]);
(ans+=f[i])%=mod;
// printf("%lld : %lld\n",i,f[i]);
}
printf("%lld\n",(ans+1+mod)%mod);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12096kb
input:
2 3 1 5 0 3 6 1 4 7 0 3 1 5 0 7 9 1 3 6 0
output:
5 8
result:
ok 2 number(s): "5 8"
Test #2:
score: 0
Accepted
time: 170ms
memory: 14052kb
input:
11120 9 336470888 481199252 1 642802746 740396295 1 396628655 579721198 0 202647942 971207868 1 46761498 268792718 0 16843338 125908043 1 717268783 787375312 0 519096230 693319712 1 762263554 856168102 1 5 274667941 279198849 0 155191459 421436316 1 140515506 286802932 0 233465964 451394766 1 105650...
output:
107 11 192 24 102 20 14 96 2 8 104 10 9 10 12 8 26 12 268 10 8 4 92 3 2 7 7 34 76 6 16 22 36 8 24 68 46 82 7 92 5 40 8 9 2 2 44 52 68 2 12 64 23 28 16 74 11 4 2 70 2 240 64 40 10 4 2 3 112 2 24 40 38 50 52 4 4 53 46 48 10 4 56 268 22 8 48 42 12 40 12 96 44 8 200 7 8 2 6 35 17 258 44 84 85 10 3 28 2 ...
result:
ok 11120 numbers
Test #3:
score: 0
Accepted
time: 416ms
memory: 36548kb
input:
5 100000 54748096 641009859 1 476927808 804928248 1 503158867 627937890 0 645468307 786026685 1 588586447 939887597 0 521365644 710156469 1 11308832 860350786 0 208427221 770562147 0 67590963 726478310 0 135993561 255361535 0 46718075 851555000 1 788412453 946936715 1 706350235 771067386 0 16233727 ...
output:
357530194 516871115 432496137 637312504 617390759
result:
ok 5 number(s): "357530194 516871115 432496137 637312504 617390759"
Test #4:
score: 0
Accepted
time: 318ms
memory: 34604kb
input:
5 100000 848726907 848750009 0 297604744 297778695 0 838103430 838114282 0 39072414 39078626 0 600112362 600483555 0 792680646 792687230 0 580164077 580183653 0 921627432 921685087 0 308067290 308143197 0 111431618 111465177 0 626175211 626270895 0 593284132 593292158 0 497427809 497437386 0 3493551...
output:
538261388 538261388 538261388 538261388 538261388
result:
ok 5 number(s): "538261388 538261388 538261388 538261388 538261388"
Test #5:
score: 0
Accepted
time: 260ms
memory: 34628kb
input:
5 100000 49947 49948 1 44822 44823 0 91204 91205 0 46672 46673 1 18538 18539 1 25486 25487 1 68564 68565 1 63450 63451 1 4849 4850 1 85647 85648 1 6019 6020 0 81496 81497 0 62448 62449 1 50039 50040 1 67911 67912 1 64304 64305 0 68727 68728 0 22340 22341 0 27265 27266 1 74123 74124 0 92270 92271 0 2...
output:
688810885 178370005 333760229 155298895 925722609
result:
ok 5 number(s): "688810885 178370005 333760229 155298895 925722609"