大意: 给定序列$a$, $a_i$为偶数代表第$\frac{a_i}{2}$种左括号, 否则为第$\frac{a_i-1}{2}$种右括号. 询问区间是否是合法括号序列.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#include <unordered_map>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
template <class T> void rd(T &x){x=0;bool f=0;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=1;c=getchar();}while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}if(f)x=-x;}
//head const int N = 4e6+10;
int n,m,q,a[N],s[N],L[N]; int main() {
scanf("%d%d%d", &n, &m,&q);
REP(i,1,n) scanf("%d",a+i);
int top = 0;
REP(i,1,n) {
if (!top) s[++top] = i;
else {
if (a[i]/2==a[s[top]]/2&&a[i]==a[s[top]]+1) --top;
else s[++top] = i;
}
L[i] = s[top];
}
REP(i,1,q) {
int x, y;
scanf("%d%d", &x, &y);
puts(L[x-1]==L[y]?"Yes":"No");
}
}

牛客 201 J Princess Principal (括号, 栈模拟)的更多相关文章

  1. 牛客国庆集训派对Day1:J:Princess Principal(栈模拟求括号匹配)

    题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号“白鸽队(Team White Pigeon)”的间谍.在没有任务的时候,她们会进行各种各样的训练,比如快速判断一个文档有没 ...

  2. [牛客] [#1108 J] [树形结构] 买一送一

    2019牛客国庆集训派对day3 链接:https://ac.nowcoder.com/acm/contest/1108/J来源:牛客网 题意 ICPCCamp 有 n 个商店,用 $1,2,..., ...

  3. 牛客国庆集训day6 B Board (模拟标记思维或找规律或分块???)

    链接:https://www.nowcoder.com/acm/contest/206/B来源:牛客网 题目描述 恬恬有一个nx n的数组.她在用这个数组玩游戏: 开始时,数组中每一个元素都是0. 恬 ...

  4. 牛客小白月赛2 G 文 【模拟】

    链接:https://www.nowcoder.com/acm/contest/86/G来源:牛客网 题目描述 Sεlιнα(Selina) 开始了新一轮的男友海选.她要求她的男友要德智体美劳样样都全 ...

  5. 牛客小白月赛13-H(单调栈+树状数组)

    题目链接:https://ac.nowcoder.com/acm/contest/549/H 题意:给一个柱状图,包括每个矩阵的宽度和高度,求能组成的最大矩阵的面积. 思路:显然最大矩阵的高一定为n个 ...

  6. 牛客网练习赛44-B(快速幂+模拟)

    题目链接:https://ac.nowcoder.com/acm/contest/548/B 题意:计算m/n小数点后k1位到k2位,1≤m≤n≤109,1<=k1<=k2<=109 ...

  7. 牛客国庆集训派对Day1 Solution

    A    Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...

  8. 10.1牛客J题

    https://www.nowcoder.com/acm/contest/201/J Description: 给你一行括号,定义了括号合格的形式,然后Q次询问,问你这个区间内括号是否合格 Solut ...

  9. [牛客网NOIP赛前集训营-普及组(第二场)]D-合法括号序列

    链接:https://www.nowcoder.com/acm/contest/165/D来源:牛客网 合法括号序列 键盘上有左括号(,右括号),和退格键-,共三个键. 牛牛希望按键n次,使得输入的字 ...

随机推荐

  1. 6.3 MRUnit写Mapper和Reduce的单元测试

    1.1  MRUnit写单元测试 作用:一旦MapReduce项目提交到集群之后,若是出现问题是很难定位和修改的,只能通过打印日志的方式进行筛选.又如果数据和项目较大时,修改起来则更加麻烦.所以,在将 ...

  2. "数字经济"云安全共测大赛Web-Writeup

    gameapp 这题首先反编译apk,简单看了看代码,主要是有startgame和score两个api,然后用模拟器(手机登不上)安装apk抓了下包,数据经过了rsa加密,所以首先用python实现r ...

  3. 以太坊geth区块链私链建立

      以太坊geth区块链私链建立 geth的github https://github.com/ethereum/go-ethereum 下载最新(1.8)的geth,windows下安装很简单 关于 ...

  4. golang sqlx查询时, struct字段冲突

    type TA struct { Id int64 `db:"id"` } type TB struct { Id int64 `db:"id"` } type ...

  5. VUE组件如何通信

    Vue父子组件如何通信? 子组件通知父组件(调用父组件方法) 在父组件使用 on(eventName)监听事件,在子组件使用emit(eventName) 触发事件 : 父组件通知子组件(调用子组件方 ...

  6. SQL-W3School-高级:SQL Date 函数

    ylbtech-SQL-W3School-高级:SQL Date 函数 1.返回顶部 1. SQL 日期 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要 ...

  7. Jenkins 自动化部署上线

    转载于互联网 jenkins自动化部署项目,通过jenkins 部署来节省运维时间,不需要手动cp上线及版本发布 Jenkins 自动化部署上线 Jenkins Jenkins 自动化部署上线一.Je ...

  8. 【403】COMP9024 Exercise

    Week 1 Exercises fiveDigit.c There is a 5-digit number that satisfies 4 * abcde = edcba, that is,whe ...

  9. Java NIO 学习笔记 读写结合补充

    小练习:nio读写文件,将fileread中的内容读取到filewrite中 try { //创建输入通道 FileInputStream fis = new FileInputStream(&quo ...

  10. python内置数据结构

    数据类型: 数值型 int float complex bool 序列对象 字符串 str 列表 list 元组 tuple 键值对 集合 set 字典dict 数值型: int.float.comp ...