QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515694 | #4879. Standard Problem | Yoralen | WA | 2ms | 10012kb | C++14 | 1.8kb | 2024-08-11 21:15:13 | 2024-08-11 21:15:14 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
#define int long long
const int N=400005,mod=998244353;
struct Tree{int l,r,ad,max;}tree[N<<2];
int f[N],n,m,g[N];
struct node{int l,r,w;}a[N];
map<int,vector<int>>mp;
void Pt(int k,int t){tree[k].ad+=t;tree[k].max+=t;}
void Pd(int k){if(tree[k].ad){Pt(k<<1,tree[k].ad);Pt(k<<1|1,tree[k].ad);tree[k].ad=0;}}
void Ph(int k){tree[k].max=max(tree[k<<1].max,tree[k<<1|1].max);}
void Build(int k,int l,int r){
tree[k].l=l,tree[k].r=r;
tree[k].ad=tree[k].max=0;
if(l==r){return;}int mid((l+r)>>1);
Build(k<<1,l,mid);Build(k<<1|1,mid+1,r);
}
void Addrg(int k,int l,int r,int v){
if(l>r||l>tree[k].r||r<tree[k].l)return;
if(l<=tree[k].l&&tree[k].r<=r){Pt(k,v);return;}
Pd(k);Addrg(k<<1,l,r,v);Addrg(k<<1|1,l,r,v);Ph(k);
}
int Askrg(int k,int l,int r){
if(l>r||l>tree[k].r||r<tree[k].l)return 0;
if(l<=tree[k].l&&tree[k].r<=r)return tree[k].max;
Pd(k);return max(Askrg(k<<1,l,r),Askrg(k<<1|1,l,r));
}
void Mofit(int k,int x,int v){
if(tree[k].l==tree[k].r){tree[k].max=max(tree[k].max,v);return;}
int mid=((tree[k].l+tree[k].r)>>1);Pd(k);
if(x<=mid)Mofit(k<<1,x,v);
else Mofit(k<<1|1,x,v);Ph(k);
}
signed main(){
int i,Ti;
scanf("%lld",&Ti);
while(Ti--){
scanf("%lld%lld",&n,&m);Build(1,0,m);
mp.clear();mp[0].push_back(0);g[0]=1;
for(i=1;i<=n;i++)f[i]=0,g[i]=0;
int ans=0,res=0;
for(i=1;i<=n;i++){
scanf("%lld%lld%lld",&a[i].l,&a[i].r,&a[i].w);
int val=Askrg(1,0,a[i].l);
Mofit(1,a[i].l,val+a[i].w);
Addrg(1,a[i].l+1,a[i].r,a[i].w);
f[i]=Askrg(1,a[i].l,a[i].r);ans=max(ans,f[i]);
for(int u:mp[f[i]-a[i].w])g[i]=(g[i]+g[u])%mod;
mp[f[i]].push_back(i);
}
for(i=1;i<=n;i++){if(f[i]==ans)res=(res+g[i])%mod;}
printf("%lld %lld\n",ans,res);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9944kb
input:
2 3 4 1 2 1 2 3 1 2 2 1 2 5 1 4 3 2 5 3
output:
3 1 6 1
result:
ok 4 number(s): "3 1 6 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 10012kb
input:
30 3 3 1 3 1 1 3 1 1 3 1 3 3 1 2 1 1 3 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 2 2 1 1 2 1 1 3 1 3 3 1 3 1 2 3 1 1 3 1 3 3 2 3 1 1 3 1 2 2 1 3 3 1 2 1 1 2 1 1 2 1 3 3 1 3 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 1 3 1 1...
output:
3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1
result:
ok 60 numbers
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9960kb
input:
20 5 5 1 5 1 1 5 1 1 4 1 1 5 1 1 5 1 5 5 2 4 1 1 5 1 1 5 1 2 4 1 2 4 1 5 5 2 4 1 1 5 1 1 5 1 2 5 1 1 3 1 5 5 1 5 1 1 5 1 2 3 1 1 5 1 1 4 1 5 5 1 4 1 1 4 1 2 5 1 1 3 1 2 4 1 5 5 2 4 1 3 3 1 1 3 1 2 4 1 4 4 1 5 5 3 3 1 1 4 1 3 3 1 2 5 1 2 5 1 5 5 2 4 1 2 3 1 4 4 1 2 4 1 2 4 1 5 5 3 3 1 3 3 1 2 4 1 1 4...
output:
5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 4 1 5 1 5 1 5 1 5 1 5 1 4 2 5 1 5 1 5 1 5 1 5 1
result:
wrong answer 30th numbers differ - expected: '1', found: '2'