挖草,AtCoder实在是太吊了~

%%%,目前只A了两题;

A题:

就是利用栈模拟一下就好了;S进栈,T的话有S就出栈,然后len减一下就好了;

#include <bits/stdc++.h>
using namespace std; char s[200020];
stack<int>q; int main()
{
scanf("%s",s+1);
int len=strlen(s+1);
int ans=0;
for(int i=1;i<=len;i++)
{
if(s[i]=='S')
{
q.push(1);
}
else
{
if(!q.empty())
{
ans+=2;
q.pop();
}
}
}
printf("%d\n",len-ans);
return 0;
}

B题【单调栈】

题意:

简单粗暴:

就是求所有区间的最小值之和

思路:

对于a[i]找他的对于区间的贡献,利用单调栈可以降低复杂度求得前面多少个比他大num1,后面多少个比他大num2,然后贡献就是区间长度*a[i];

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; const int N=2e5+10; struct asd{
LL pre;
LL num;
LL next;
LL k;
};
stack<asd>q; LL t[N];
int n; int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&t[i]);
LL ans=0;
asd tmp;
tmp.num=t[1];
tmp.pre=tmp.next=1;
tmp.k=1;
q.push(tmp);
LL x=0,y=0;
for(LL i=2;i<=n;i++)
{
asd tmp1;
tmp1.num=t[i];
tmp1.pre=tmp1.next=1;
tmp1.k=i;
while(!q.empty()&&tmp1.num<=q.top().num)//如果说这个元素是小于栈顶的,那么它里面的栈就要被更新,这个元素的pre也要被更新
{
tmp=q.top();
q.pop();
if(!q.empty())
q.top().next+=tmp.next;
tmp1.pre+=tmp.pre;
ans+=tmp.pre*tmp.next*tmp.num;
}
q.push(tmp1);
}
while(!q.empty())
{
tmp=q.top();
q.pop();
if(!q.empty())
q.top().next+=tmp.next;
ans+=tmp.num*tmp.next*tmp.pre;
}
printf("%lld\n",ans);
}

AtCoder Grand Contest 005【A栈模拟,B单调栈】的更多相关文章

  1. AtCoder Grand Contest 005

    AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...

  2. AtCoder Grand Contest 005 C - Tree Restoring

    题目传送门:https://agc005.contest.atcoder.jp/tasks/agc005_c 题目大意: 给定一个长度为\(N\)的整数序列\(A_i\),问能否构造一个\(N\)个节 ...

  3. Atcoder Grand Contest 005 E - Sugigma: The Showdown(思维题)

    洛谷题面传送门 & Atcoder 题面传送门 记先手移动棋子的树为红树,后手移动棋子的树为蓝树. 首先考虑一个性质,就是如果与当前红色棋子所在的点相连的边中存在一条边,满足这条边的两个端点在 ...

  4. AtCoder Grand Contest 005题解

    传送门 \(A\) 咕咕 const int N=5e5+5; char s[N];int res,n,sum; int main(){ scanf("%s",s+1),res=n ...

  5. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  6. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

  7. AtCoder Grand Contest 002

    AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. ...

  8. AtCoder Grand Contest 014

    AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中 ...

  9. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

随机推荐

  1. Linux 中权限控制实例

    前言 前文对 Linux 中的权限进行了较为透彻的分析.而本文,则在前文的基础上,具体说明如何在代码中进行权限控制. 下面的代码涉及到以下几个方面: 1. 创建文件时设置文件权限 2. 修改文件的默认 ...

  2. cvpr2014

    http://www.cvpapers.com/cvpr2014.html 吴佳俊 楼天城

  3. 图像处理之opencv---mat、cvmat、IplImage之间的转换

    一.Mat类型:矩阵类型,Matrix.  在openCV中,Mat是一个多维的密集数据数组.可以用来处理向量和矩阵.图像.直方图等等常见的多维数据. Mat有3个重要的方法: 1.Mat mat = ...

  4. angular cannot get /

    每次遇到这问题都一脸懵逼,好像自己啥都没改咋就悲剧了 目前知道的办法是在命令行运行ng serve,它会告诉你详细错误 因为我是通过asp.net core的集成环境运行的,它没显示出详细错误

  5. [Phoenix] 一、快速入门

    Phoenix是一个开源的HBASE SQL层.Phoeinx可以用标准的JDBC API替代HBASE client API来创建表,插入和查询HBASE中的数据. Phoenix作为应用层和HBA ...

  6. 一步步玩pcDuino3--uboot下的ping,加入命令能够接受来自host的ping

    uboot是一个很优秀的开源项目.不只能够学习bootloader.嵌入式,各种总线协议. 还能够了解网络协议栈.在嵌入式开发中,常常使用uboot的tftp和nfs来加快开发的效率.那么在tftp能 ...

  7. appium(13)- server config

    //本文讲解:启动server时,如何配置capabilities 和 flag.可以将不同client端需要的通用的capabilities都放到server端配置. Requirements In ...

  8. Adjusting Network Connection

    Adjusting Network Connection The Selenium Mobile JSON Wire Protocol Specification supports an API fo ...

  9. Vue中的methods、watch、computed

    看到这个标题就知道这篇文章接下来要讲的内容,我们在使用vue的时候methods.watch.computed这三个特性一定经常使用,因为它们是非常的有用,但是没有彻底的理解它们的区别和各自的使用场景 ...

  10. java HttpClient GET请求

    HttpClient GET请求小实例,先简单记录下. package com.httpclientget; import java.io.IOException; import org.apache ...