传送门

文章目录

  • 题意:
  • 思路:

题意:

思路:

紧跟刘爷脚步补题。
不难想到用链表维护下一个数是什么,这样就跟以前做过的一个题差不多了,首先将初始的时候删掉的点的前一个点即为题目中的AAA入队,让后删掉这个点只会影响他之后的一个点,用链表维护一下每个点下一个点在哪里,直接判断就好啦。

// Problem: B. Playlist
// Contest: Codeforces - Codeforces Round #709 (Div. 1, based on Technocup 2021 Final Round)
// URL: https://codeforces.com/problemset/problem/1483/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<assert.h>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
int a[N],nt[N],pr[N],st[N];
int cnt[N];
queue<int>q;
vector<int>v;int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d",&n);for(int i=0;i<n;i++) st[i]=0,cnt[i]=0;v.clear();for(int i=0;i<n;i++) scanf("%d",&a[i]),nt[i]=(i+1)%n;for(int i=0;i<n;i++) {if(__gcd(a[i],a[(i+1)%n])==1)q.push(i),st[(i+1)%n]=1,nt[i]=nt[nt[i]],v.pb((i+1)%n),i++;}while(q.size()) {int u=q.front(); q.pop();cnt[u]++;if(st[u]) continue;if(__gcd(a[u],a[nt[u]])==1) {v.pb(nt[u]);st[nt[u]]=1;nt[u]=nt[nt[u]];q.push(u);} }int sum=0;//for(int i=1;i<=n;i++) sum+=cnt[i];//assert(sum<=n*4);printf("%d",v.size());for(auto x:v) printf(" %d",x+1);puts("");}return 0;
}
/**/

Codeforces Round #709 (Div. 1) B. Playlist 链表维护 + bfs相关推荐

  1. Codeforces Round #709 (Div. 1) C. Skyline Photo dp + 单调栈优化

    传送门 文章目录 题意: 思路: 题意: 思路: 首先一个非常明显的dpdpdp式子就是f[i]=max(f[j]+val(j+1,i))f[i]=max(f[j]+val(j+1,i))f[i]=m ...

  2. Codeforces Round #636 (Div. 3) E. Weights Distributing 思维 + bfs

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5 思路: 怎么感觉每场div3div3div3都有一个巧妙的图论题. 首先如果只有两 ...

  3. Codeforces Round #646 (Div. 2) E(贪心,bfs)

    Codeforces Round #646 (Div. 2) E 题目大意: 给一棵树,每个节点有三个权值 A,B,C, (B,C为0或1),每次你可以花费 A[u] *k的代价让A子树中的任意 k ...

  4. Codeforces Round #709 (Div. 2, based on Technocup 2021 Final Round) 题解

    文章目录 A. Prison Break B. Restore Modulo C. Basic Diplomacy D. Playlist E. Skyline Photo F. Useful Edg ...

  5. Codeforces Round #709 (Div. 1, based on Technocup 2021 Final Round) A. Basic Diplomacy

    传送门 文章目录 题意: 思路: 题意: 有nnn个小朋友,让后你要在mmm天中每天都选择一个小朋友,给出这mmm天都可以选哪个小朋友,每个小朋友选的次数不超过⌈m2⌉\left \lceil \fr ...

  6. Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs

    B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...

  7. Codeforces Round #309 (Div. 1)D. Nudist Beach 二分+bfs

    题目:http://codeforces.com/contest/553/problem/D 在一个无向图中,有若干坏点,选择一个不包含坏点的集合,使得集合中p值最小的点的p值最大.一个点的p值=集合 ...

  8. Codeforces Round #467 (Div. 1): B. Sleepy Game(BFS+有向图判环)

    题意(经过转换):给你一个n个点m条边的有向图,再给你一个起点x,问存不存在一条路径满足①路径中有奇数条边:②终点的出度为0,如果存在输出Win,并在第二行输出这个路径(可能不唯一输出任意一种),否则 ...

  9. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

最新文章

  1. 远程控制 vc++实现
  2. 必须认识的http请求包
  3. UVA 617 - Nonstop Travel(数论+暴力枚举)
  4. node.js Centos安装
  5. 华为任职资格_华为采购总部专业任职资格标准|
  6. 沈阳药科大学计算机二级好考吗,沈阳药科大学考研难吗?一般要什么水平才可以进入?...
  7. 什么是激光雷达技术?
  8. html京东下拉菜单设置,div css下拉导航菜单(图+演示)
  9. 阿里火力全开 IoT!
  10. 查找包含具有指定名称的列的所有表 - MS SQL Server
  11. The ‘state_publisher‘ executable is deprecated. Please use ‘robot_state_publisher‘ instead
  12. 看见几篇文章,收藏一下。
  13. GBaseDataStudio 管理工具简介
  14. CYQ.Data V5 分布式自动化缓存设计介绍
  15. PHP过滤昵称中emoji表情
  16. TCP三次握手详解-深入浅出(有图实例演示)
  17. cmake简洁教程 - 第五篇
  18. 【JZOJ】【卡特兰数】【高精】WZK打雪仗
  19. MySQL数据库优化-运维角度浅谈
  20. 毕业设计-基于深度学习的垃圾邮件过滤系统的设计与实现

热门文章

  1. mysql profiles清空_MYSQL 使用show profiles 分析性能
  2. 可编程智能小车,100种玩法,从3岁玩到15岁,培养孩子“最强大脑”
  3. 如果有人问你什么是大数据?不妨说说这10个典型的大数据案例
  4. python序列元素的编号称为_Python序列
  5. 计算机老师开场白试讲视频,教师招考试讲模版之开场白
  6. 正弦波 程序 角度传感器_激光位移传感器的原理及应用领域
  7. java try finally connectoin close_Java SocketChannel類代碼示例
  8. android photopicker怎么修改状态栏,有没有办法阻止UIImagePickerController更改状态栏样式?...
  9. k8s滚动升级_k8s deployment 滚动更新
  10. 攻城时服务器维护,8月31日服务器维护更新公告