-
个人简介
死亡不是结束,而是另一种开始。
#include <bits/stdc++.h> const int N = 1e7 + 9, INF = 1e9; int a[N], b[N], q1[N], f1, r1, q2[N], f2, r2; int main() { int n, k, ans = INF; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= n; i++) scanf("%d", b + i); int lo = 1, hi = 0; while (hi < n) { ++hi; while (f1<r1 and a[q1[r1-1]]>=a[hi]) --r1; q1[r1++] = hi; while (f2<r2 and b[q2[r2-1]]<=b[hi]) --r2; q2[r2++] = hi; while (a[q1[f1]]+k<=b[q2[f2]] and lo<=hi) { ans = std::min(ans, hi-lo+1); ++lo; if (f1<r1 and q1[f1]<lo) ++f1; if (f2<r2 and q2[f2]<lo) ++f2; } } if (ans == INF) puts("So Sad!"); else printf("%d", ans); return 0; }
#include<bits/stdc++.h> #define ll long long #define int ll #define L xd[x].l #define R xd[x].r #define mid (l+r>>1) #define lc L,l,mid #define rc R,mid+1,r #define OK Ll<=l&&r<=Rr #define Root 1,1,n #define rep(x,y,z) for(int x=(y);x<=(z);x++) #define per(x,y,z) for(int x=(y);x>=(z);x--) #define pb push_back #define ull unsigned ll #define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i]) #define E(x) for(auto y:p[x]) #define Pi pair<int,int> #define ui unsigned ll inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;} inline void pf(ll x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);} const int N =2e5+5,M=5e6+5,inf=(1LL<<31)-1; const ll llf=1e18,mod=1e9+7; using namespace std; int T=read(),n,m,q,a[N]; struct edge{ int x,y,w; }e[N]; int s[N],tp,f[N],out[N]; inline int find(int x){ return f[x]==x?x:f[x]=find(f[x]); } struct node{ int s,t,w,id; }sol[N]; inline bool cmp(edge a,edge b){ return a.w<b.w; } inline bool Cmp(node c,node d){ return a[c.s]+c.w<a[d.s]+d.w; } signed main(){ while(T--){ n=read(),m=read(); rep(i,1,n)a[i]=read(),f[i]=i; rep(i,1,m)e[i].x=read(),e[i].y=read(),e[i].w=max(a[e[i].x],a[e[i].y]); sort(e+1,e+m+1,cmp); q=read(); rep(i,1,q)sol[i].s=read(),sol[i].t=read(),sol[i].w=read(),sol[i].id=i; sort(sol+1,sol+q+1,Cmp); int Ll=1; rep(i,1,q){ while(Ll<=m&&e[Ll].w<=a[sol[i].s]+sol[i].w)f[find(e[Ll].x)]=find(e[Ll].y),Ll++; out[sol[i].id]=(find(sol[i].s)==find(sol[i].t)); } rep(i,1,q)if(out[i])cout <<"Yes\n"; else cout <<"No\n"; cout <<'\n'; } return 0; }
Administrator [誓死坚守游戏下载_Until We Die中文版下载[策略游戏]-下载之家 (downza.cn)]
http://www.ddooo.com/softdown/200103.htm
next_permutation(a+1,a+1+n) 指针 - OI Wiki (oi-wiki.org) https://www.luogu.org https://www.luogu.com.cn/problem/P2483
#include using namespace std; const int MAXN=65535; const int INF=1000050; long long l,r; long long a,b,c,d,e,f; long long p[MAXN],num; bitset<INF>v; void ols(){ v.reset(); for(int i=2;i<=MAXN;i++){ if(!v[i])p[++num]=i; for(int j=1;j<=num;j++){ if(i*p[j]>MAXN)break; v[i*p[j]]=1; if(i%p[j]==0)break; } } } void ass(){ v.set(); for(long long i=1;i<=num;i++){ for(long long j=r/p[i];j>1&&p[i]*j>=l;j--)v[p[i]*j-l]=false; } } int main(){ ols(); while(cin>>l>>r){ if(l==1)l=2; ass(); a=-1000000,b=1000000,c=0,d=0,e=0,f=0; for(long long i=l;i<=r;i++){ if(v[i-l]){ e=f; f=i; if(e>0){ if(f-e<b-a)b=f,a=e; if(f-e<d-c)d=f,c=e; } } } if(a<0)puts("There are no adjacent primes."); else printf("%lld,%lld are closest, %lld,%lld are most distant.\n",a,b,c,d); } return 0; }
#include <iostream> #include <cstring> #include <algorithm> #include <queue> const int N = 1e5 + 9, M = 1e6 + 9; int n, m, s, tot; int head[N], dis[N]; bool vis[N]; struct Edge { int ver, edge, next; } g[M]; std::priority_queue < std::pair <int, int> > que; void add(int x, int y, int z) { g[++tot] = {y, z, head[x]}; head[x] = tot; } void Dijkstra() { memset(dis, 0x3F, sizeof dis); dis[s] = 0; que.push(std::make_pair(0, s)); while (!que.empty()) { int x = que.top().second; que.pop(); if (vis[x]) continue; vis[x] = true; for (int i = head[x]; i; i = g[i].next) { int y = g[i].ver, z = g[i].edge; if (dis[y] > dis[x] + z) { dis[y] = dis[x] + z; que.push(std::make_pair(-dis[y], y)); } } } } int main() { scanf("%d%d%d", &n, &m, &s); for (int i = 1, u, v, w; i <= m; i++) scanf("%d%d%d", &u, &v, &w), add(u, v, w); Dijkstra(); for (int i = 1; i <= n; i++) printf("%d ", dis[i]); return 0; }
-
通过的题目
- 930
- 931
- 932
- 973
- 986
- 987
- 1040
- 1074
- 1123
- 1127
- 1160
- 1161
- 1162
- 1166
- 1167
- 1184
- 1208
- 1213
- 1222
- 1226
- 1235
- 1245
- 1249
- 1250
- 1285
- 1305
- 1308
- 1310
- 1311
- 1324
- 1337
- 1348
- 1379
- 1380
- 1383
- 1388
- 1389
- 1475
- 1476
- 1477
- 1480
- 1494
- 1495
- 1512
- 1516
- 1524
- 1527
- 1528
- 1529
- 1534
- 1535
- 1551
- 1552
- 1553
- 1554
- 1555
- 1556
- 1557
- 1558
- 1564
- 1579
- 1580
-
最近活动
-
最近编写的题解
题目标签
- 基础问题
- 46
- 分支问题
- 42
- 简单循环
- 28
- 字符串
- 19
- 数组问题
- 13
- 动态规划
- 13
- 需要找规律的循环
- 12
- 数据结构
- 10
- 嵌套循环
- 7
- 搜索
- 6
- 深搜
- 6
- noip复赛
- 6
- 背包
- 6
- 树结构
- 6
- 递归
- 4
- 哈希
- 4
- 并查集
- 4
- 数论
- 4
- 堆
- 4
- 位运算
- 4