QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778961 | #7905. Ticket to Ride | byron10000 | WA | 3ms | 3884kb | C++14 | 2.0kb | 2024-11-24 16:53:57 | 2024-11-24 16:53:58 |
Judging History
answer
#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
typedef pair<int,int> pii;
typedef __int128 i128;
const int MAXN=1e4+10; const long NINF=0xc0c0c0c0c0c0c0c0;
int n,m; long ans[MAXN];
struct Itv{ int l,r,a; } A[MAXN];
vector<Itv> vec[MAXN];
struct DSU{
int fa[MAXN];
void init(){ iota(fa,fa+n+1,0); }
int find(int u){ return fa[u]==u?u:fa[u]=find(fa[u]); }
void merge(int u,int v){
if((u=find(u))!=(v=find(v))) fa[v]=u;
}
} dsu;
long F[MAXN],G[MAXN],D[MAXN];
int nxt[MAXN];
void case_main(){
cin>>n>>m,n++;
RNG(i,1,n) vec[i].clear();
RNG(i,1,m) cin>>A[i].l>>A[i].r>>A[i].a,A[i].l++,A[i].r++,vec[A[i].r].push_back(A[i]);
auto upd=[](int i,int a){
i=dsu.find(i);
D[i]+=a;
while(nxt[i]&&D[i]+G[i]>G[nxt[i]]) D[i]+=D[nxt[i]],dsu.merge(i,nxt[i]),nxt[i]=nxt[nxt[i]];
};
fill(F,F+n+1,NINF),F[0]=0;
RNG(k,1,n-1){
copy(F,F+n+1,G); fill(D,D+n+1,0); F[0]=NINF;
dsu.init();
RNG(i,1,n){
for(auto x:vec[i]) upd(x.l-1,x.a);
int j=dsu.find(i-1);
F[i]=G[j]+D[j];
if(G[j]+D[j]>G[i]) dsu.merge(j,i);
else nxt[j]=i;
}
ans[k]=F[n];
}
RNG(k,1,n-1) cout<<ans[n-k]<<" ";
cout<<"\n";
}
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
// freopen("/dev/null","w",stderr);
#else
// freopen("yesterday.in","r",stdin);
// freopen("yesterday.out","w",stdout);
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int cas; cin>>cas;
RNG(_,1,cas) case_main();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3884kb
input:
2 4 3 0 2 3 3 4 2 0 3 1 3 1 1 3 100
output:
2 3 5 6 0 100 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3880kb
input:
1000 2 9 0 2 396628655 1 2 268792718 0 2 16843338 1 2 717268783 0 1 693319712 0 1 856168102 1 2 407246545 1 2 527268921 0 1 536134606 6 2 2 5 451394766 0 5 695984050 9 7 0 6 73936815 2 9 505041862 4 5 223718927 5 7 179262261 3 5 449258178 0 5 493128 0 3 994723920 6 6 3 5 433389755 2 4 773727734 4 5 ...
output:
2085622420 4419671380 0 0 451394766 451394766 1147378816 1147378816 223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 127680943 773727734 1334798432 2227456393 2675644351 2675644351 976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418...
result:
wrong answer 6th lines differ - expected: '812812058 812812058', found: '1430659838 1430659838 '