当前位置:网站首页>PAT甲级 1057 Stack
PAT甲级 1057 Stack
2022-08-08 00:53:00 【九是否非随机的称呼】
block,计数的时候使用块计算总和,不要单个相加
#include<iostream>
#include<vector>
#include<stack>
#include<string>
#include<map>
#include<bits/stdc++.h>
using namespace std;
int position[100001];
int partion[100001/316+1];
int part = 316;
int peekmedian(int h){
int i=0, j=0;
int sum = 0;
while(sum < h)
sum += partion[i++];
sum -= partion[i-1];
j = (i-1) * part;
while(sum < h)
sum +=position[j++];
return j;
}
int main(void){
string s, s0;
stack<int> sk;
int i, j, m, n, t, counts, x, y, cnt=0, sum;
cin>>m;
memset((void *)position, 0, sizeof(int) * 100001);
memset((void *)partion, 0, sizeof(int) * 100001/316+1);
for(i=0; i<m; i++){
cin>>s;
if(s[1]=='o'){
if(sk.size()==0){
cout<<"Invalid"<<endl;
continue;
}else{
y = sk.top();
cout<<y<<endl;
position[y] -= 1;
partion[y/part] -= 1;
sk.pop();
}
}else if(s[1]=='e'){
if(sk.size()==0) cout<<"Invalid"<<endl;
else{
if(sk.size()%2!=0)
sum = peekmedian((sk.size()+1)/2);
else
sum = peekmedian(sk.size()/2);
cout<<sum-1<<endl;
}
}
else{
scanf("%d", &y);
position[y] += 1;
partion[y/part] += 1;
sk.push(y);
}
}
return 0;
}边栏推荐
猜你喜欢

Chapter 3 Matrix Compression

阿包的夜宵

Octopus Application Chain|Content Curation Collaboration Organization DISCOVOL DAO Mainnet Launched in August

Let’s talk about the anti-reverse circuit in combination with the actual situation (summary of the anti-reverse circuit)

PyTorch 源码解读之 torch.utils.data:解析数据处理全流程(非常好,一篇足够)

嵌入式分享合集31-串口

SAP 的MPN功能

leetcode-每日一题636. 函数的独占时间(模拟栈)

【愚公系列】2022年08月 Go教学课程 032-结构体方法继承

Flutter之图片选择器、支持多语言国际化、动画
随机推荐
High performance cloud storage MinIO combat - native data object
Good news | Hongshi data has obtained CMMI level 3 certification!Welcome to the self-developed unified operation and maintenance monitoring platform!
Pour water problem (summer vacation daily question 17)
解决:ERROR: Cannot uninstall ‘certifi‘. It is a distutils installed project and thus we cannot accurat
ip and userId in awk statistics log--analyze the behavior of users maliciously brushing the interface
pycharm connect to remote server
Is it safe to snowball account!
结合实际聊聊防反接电路(防反接电路总结)
leetcode-每日一题636. 函数的独占时间(模拟栈)
高数_证明_柯西中值定理
2 Param 注解的使用规范
陈强教授《机器学习及R应用》课程 第十章作业
Octopus Network Progress Report | 2022.7.1-7.31
Rdkit common commands/parameter settings
喜讯|宏时数据获得CMMI3级认证!欢迎了解自研统一运维监控平台!
有关原码,反码,补码那些事
Detailed explanation of SQL DNSlog injection
STM32F103C8T6模拟SPI控制6针/7针0.96寸OLED显示屏
SVG基本图形
继承关系下构造方法的访问特点注意:把this()访问本类其他成员方法也加进去
https://github.com/ZouJiu1/PAT