ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205086 | #3645. 单调图 | nullptr_qwq | 100 | 4542ms | 25512kb | C++11 | 3.2kb | 2024-06-23 08:40:47 | 2024-06-23 13:02:09 |
answer
// 私は猫です
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define dF(i,a,b) for(int i=(a);i>=(b);i--)
#define wh(lzm) while(lzm--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
using namespace std;
ll read(){
ll 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<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
const int mod=998244353,maxn=200005;
inline void chkmax(int &x,int y){ x=max(x,y); }
inline void chkmin(int &x,int y){ x=min(x,y); }
vector<pii>g[maxn];
int n,m,a[maxn],b[maxn],c[maxn],vis[maxn],lsh[maxn],tot;
void dij(int *d,int s){
priority_queue<pii>q;
F(i,1,n) vis[i]=0,d[i]=inf;
q.push(mkp(d[s]=0,s));
while(!q.empty()){
int u=q.top().se; q.pop();
if(vis[u]) continue;
vis[u]=1;
for(auto it=g[u].begin();it!=g[u].end();++it){
const int v=it->first,w=it->second;
if(d[v]>d[u]+w) d[v]=d[u]+w,q.push(mkp(-d[v],v));
}
}
}
struct N1{
int x,y,z;
bool operator<(const N1 &rhs)const{
if(x^rhs.x) return x<rhs.x;
if(y^rhs.y) return y<rhs.y;
return z<rhs.z;
}
};
struct node{
int x,y,z,id,siz;
bool operator<(const node &rhs)const{
if(x^rhs.x) return x<rhs.x;
if(y^rhs.y) return y<rhs.y;
return z<rhs.z;
}
};
bool cmp(node A,node B){
if(A.y^B.y) return A.y<B.y;
if(A.z^B.z) return A.z<B.z;
return A.x<B.x;
}
int fl[maxn];
vector<node>vec;
void Solve(int l,int r){
if(l==r) return;
int mid=(l+r)>>1;
Solve(l,mid),Solve(mid+1,r);
vector<node>A,B;
F(i,l,mid) A.push_back(vec[i]);
F(i,mid+1,r) B.push_back(vec[i]);
sort(A.begin(),A.end(),cmp),sort(B.begin(),B.end(),cmp);
int mn=inf,lsz=A.size(),rsz=B.size(),p=-1;
F(i,0,rsz-1){
for(;p+1<lsz&&A[p+1].y<=B[i].y;++p) chkmin(mn,A[p+1].z);
if(mn<=B[i].z) fl[B[i].id]=1;
}
}
void solve(){
n=read(),m=read();
F(i,1,m){
int u=read(),v=read(),w=read();
g[u].push_back(mkp(v,w)),g[v].push_back(mkp(u,w));
}
dij(a,1),dij(b,2),dij(c,3);
tot=0; F(i,1,n) lsh[++tot]=a[i]; sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1; F(i,1,n) a[i]=lower_bound(lsh+1,lsh+tot+1,a[i])-lsh;
tot=0; F(i,1,n) lsh[++tot]=b[i]; sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1; F(i,1,n) b[i]=lower_bound(lsh+1,lsh+tot+1,b[i])-lsh;
tot=0; F(i,1,n) lsh[++tot]=c[i]; sort(lsh+1,lsh+tot+1),tot=unique(lsh+1,lsh+tot+1)-lsh-1; F(i,1,n) c[i]=lower_bound(lsh+1,lsh+tot+1,c[i])-lsh;
map<N1,int>mp;
F(i,1,n) ++mp[(N1){a[i],b[i],c[i]}];
int m=0;
for(auto it=mp.begin();it!=mp.end();++it) vec.push_back((node){it->first.x,it->first.y,it->first.z,m++,it->second});
// F(i,0,m-1) printf("%d %d %d %d %d\n",vec[i].x,vec[i].y,vec[i].z,vec[i].id,vec[i].siz);
Solve(0,m-1);
int ans=0;
F(i,0,m-1) if(!fl[i]) ans+=vec[i].siz;
printf("%d",ans);
}
signed main(){
int sjy=1;
cmh(sjy) solve();
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 5960kb
input:
250 300 224 221 81 7 224 11 19 221 40 186 7 96 149 19 86 143 149 75 111 221 47 4 221 84 87 224 28 24...
output:
33
result:
ok single line: '33'
Test #2:
score: 5
Accepted
time: 0ms
memory: 5960kb
input:
250 300 15 55 47 44 15 29 36 44 39 147 15 76 114 55 20 47 15 99 5 36 44 185 55 37 224 5 67 113 147 4...
output:
27
result:
ok single line: '27'
Test #3:
score: 5
Accepted
time: 0ms
memory: 5960kb
input:
250 300 145 60 26 26 145 19 131 26 62 73 131 66 228 26 4 250 60 32 30 73 32 210 26 33 161 131 68 70 ...
output:
33
result:
ok single line: '33'
Test #4:
score: 5
Accepted
time: 3ms
memory: 5964kb
input:
250 300 212 227 26 70 227 83 122 70 31 245 122 1 162 122 18 89 212 45 233 89 78 159 162 49 87 70 89 ...
output:
37
result:
ok single line: '37'
Test #5:
score: 5
Accepted
time: 3ms
memory: 6164kb
input:
1800 2000 481 73 36 1145 481 90 899 481 12 855 899 71 117 1145 87 17 855 51 1223 17 13 1708 1145 55 ...
output:
43
result:
ok single line: '43'
Test #6:
score: 5
Accepted
time: 6ms
memory: 6172kb
input:
1800 2000 1533 1556 16 1551 1556 96 1076 1556 37 31 1551 83 40 1076 18 1648 1551 97 1760 1533 89 141...
output:
58
result:
ok single line: '58'
Test #7:
score: 5
Accepted
time: 2ms
memory: 6192kb
input:
1800 2000 554 498 60 442 554 18 54 498 9 1798 54 33 422 1798 14 1696 54 41 201 1798 40 297 1798 63 8...
output:
49
result:
ok single line: '49'
Test #8:
score: 5
Accepted
time: 266ms
memory: 22416kb
input:
100000 99999 5092 35397 69 59669 5092 13 66060 5092 45 45290 66060 57 86709 5092 79 37616 86709 66 7...
output:
5616
result:
ok single line: '5616'
Test #9:
score: 5
Accepted
time: 240ms
memory: 22268kb
input:
100000 99999 76853 94 59 27726 94 13 90492 76853 33 97933 90492 71 46476 97933 18 6568 90492 37 3242...
output:
3202
result:
ok single line: '3202'
Test #10:
score: 5
Accepted
time: 260ms
memory: 22352kb
input:
100000 99999 20874 85984 48 8458 20874 88 50743 8458 100 41101 8458 84 8267 20874 86 30201 8458 55 3...
output:
4659
result:
ok single line: '4659'
Test #11:
score: 5
Accepted
time: 285ms
memory: 19748kb
input:
100000 200000 53018 80768 61 5832 80768 43 2997 80768 91 66393 80768 56 81366 5832 59 85664 5832 16 ...
output:
40
result:
ok single line: '40'
Test #12:
score: 5
Accepted
time: 356ms
memory: 24712kb
input:
100000 200000 28908 36036 66 91872 36036 84 1622 28908 74 60237 1622 1 17200 28908 44 89734 28908 82...
output:
39
result:
ok single line: '39'
Test #13:
score: 5
Accepted
time: 303ms
memory: 21512kb
input:
100000 200000 80169 49117 81 59533 80169 11 38687 80169 66 73361 49117 69 86848 80169 39 97609 73361...
output:
37
result:
ok single line: '37'
Test #14:
score: 5
Accepted
time: 331ms
memory: 23412kb
input:
100000 200000 8518 10111 89 80152 8518 82 28398 8518 42 64281 8518 89 79057 10111 31 67454 64281 64 ...
output:
52
result:
ok single line: '52'
Test #15:
score: 5
Accepted
time: 380ms
memory: 25508kb
input:
100000 200000 63008 51968 67 14619 63008 33 38273 63008 86 30436 51968 98 95240 30436 21 44387 51968...
output:
118
result:
ok single line: '118'
Test #16:
score: 5
Accepted
time: 562ms
memory: 25508kb
input:
100000 200000 38428 6838 6 57875 38428 62 23341 6838 42 77486 57875 67 36886 57875 99 35263 6838 58 ...
output:
106
result:
ok single line: '106'
Test #17:
score: 5
Accepted
time: 436ms
memory: 25492kb
input:
100000 200000 29745 3984 50 23260 3984 62 53496 23260 79 81207 53496 13 79920 81207 44 90071 53496 1...
output:
99
result:
ok single line: '99'
Test #18:
score: 5
Accepted
time: 349ms
memory: 25476kb
input:
100000 200000 46691 643 96 325 46691 74 74789 325 7 65177 46691 54 98613 46691 46 69449 643 77 60913...
output:
62
result:
ok single line: '62'
Test #19:
score: 5
Accepted
time: 393ms
memory: 25500kb
input:
100000 200000 33629 97358 73 44862 33629 12 25151 33629 46 87268 25151 34 81508 25151 83 45636 81508...
output:
160
result:
ok single line: '160'
Test #20:
score: 5
Accepted
time: 367ms
memory: 25512kb
input:
100000 200000 68252 47666 98 62764 68252 87 84831 68252 91 49616 68252 73 58627 68252 71 33313 68252...
output:
166
result:
ok single line: '166'
Extra Test:
score: 0
Extra Test Passed