我只能说真的看不懂题解的做法
我的做法就是线段树维护,毕竟每个数的顺序不变嘛
那么单点维护 区间剩余卡片和最小值

每次知道最小值之后,怎么知道需要修改的位置呢
直接从每种数维护的set找到现在需要修改的数的在初始卡片的位置

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define MP(x, y) make_pair(x, y)
#define lson l,m, rt<<1
#define rson m+1, r, rt<<1|1
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
int MOD;
int A[N];
int Min[N << 2];
int Sum[N << 2];
void Build(int l, int r, int rt) {
if(l == r) {
Min[rt] = A[l]; Sum[rt] = 1;
return;
}
int m = (l + r) >> 1;
Build(lson); Build(rson);
Sum[rt] = Sum[rt << 1] + Sum[rt << 1|1];
Min[rt] = min(Min[rt <<1] , Min[rt << 1|1]);
}
void Update(int pos, int l, int r, int rt) {
if(l == r) {
Min[rt] = INF; Sum[rt] = 0;
return;
}
int m = (l + r) >> 1;
if(pos <= m) Update(pos, lson);
else Update(pos, rson);
Sum[rt] = Sum[rt<<1] + Sum[rt<<1|1];
Min[rt] = min(Min[rt<<1], Min[rt<<1|1]);
}
int Total(int pos, int l, int r, int rt) {
if(pos == 0) return 0;
if(pos == r) {
return Sum[rt];
}
int m = (l + r) >> 1;
if(pos <= m) return Total(pos, lson);
else return Sum[rt<<1] + Total(pos, rson);
} map<int, set<int> > mp;
set<int> ::iterator it; int main() {
int n;
while(~scanf("%d", &n)) {
ll ans = 0;
mp.clear();
for(int i = 1; i <= n; ++i) {
scanf("%d",&A[i]);
mp[A[i]].insert(i);
}
Build(1, n, 1); int pos = 1;
for(int i = 1; i <= n; ++i) {
int tar = Min[1]; int nwpos;
it = mp[tar].lower_bound(pos); if(it == mp[tar].end()) {
it = mp[tar].begin();
}
nwpos = *it;
mp[tar].erase(it); // printf("%d %d\n", tar, nwpos); Update(nwpos, 1, n, 1);
int t1 = Total(nwpos, 1,n,1); int t2 = Total(pos - 1, 1,n,1);
// printf("%d %d\n", t1, t2);
if(pos <= nwpos) {
ans += t1 - t2 + 1;
}else {
ans += Sum[1] - t2 + t1 + 1;
}
pos = nwpos;
} printf("%d\n", ans);
}
return 0;
}

Codeforces Round #424 Div2 E. Cards Sorting的更多相关文章

  1. codeforces round #424 div2

    A 暴力查询,分三段查就可以了 #include<bits/stdc++.h> using namespace std; ; int n, pos; int a[N]; int main( ...

  2. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) E. Cards Sorting 树状数组

    E. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Cards Sorting(树状数组)

    Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  9. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

随机推荐

  1. trie 树 模板

    #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...

  2. VUE 2.0 引入高德地图,自行封装组件

    1. 高德地图官网 申请帐号, 申请相应(JavaScript API)的 Key 2. 在项目中引入, 这里和其他的引入不同的是 直接在 index.html, 不是在 main.js 引入, 博主 ...

  3. Python面向对象篇(2)-继承

    在发表本篇随笔的时候,距离上一次发已经有一个多月了,很多朋友私信我为什么不持续更新了,在这里先跟大家说声抱歉.因为年底的工作较为繁重,实在分不出精力,更重要的也是在思考后面进阶的部分要按怎样的顺序写, ...

  4. 【Tools】Pycharm 2018专业版 linux安装教程 附2018专业版密钥

    Linux安装pycharm2018专业版 1. 下载安装包 Pycharm下载地址:http://www.jetbrains.com/pycharm/download/ 2.终端打开你的安装包所在路 ...

  5. 【linux之设备,分区,文件系统】

    一.设备 IDE磁盘的设备文件采用/dev/hdx来命名,分区则采用/dev/hdxy来命名,其中x表示磁盘(a是第一块磁盘,b是第二块磁盘,以此类推), y代表分区的号码(由1开始,..3以此类推) ...

  6. Java基础点滴

    1. 关于interface的定义 [修饰符] interface 接口名 [extends 父接口名列表]{ [public] [static] [final] 常量;[public] [abstr ...

  7. dnsmasq 做 DHCP 服务器

    /etc/dnsmasq.conf #DNS服务器的地址,就是我的热点的地址 listen-address=192.168.1.1 #设置DHCP分配的地址范围和时间 dhcp-range=192.1 ...

  8. LNMP搭建04 -- 配置Nginx支持PHP

    首先建立存放网页文件的目录,执行 mkdri /usr/local/server/www  然后进入到该目录中 cd /usr/local/server/www 然后创建一个测试文件: phpinfo ...

  9. Ubuntu系统下crontab的使用

    最近一个项目,需要用到一个定时任务,先说crontab的常用命令. crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数 crontab -l //列出 ...

  10. LaTeX 各种命令,符号

    函数.符号及特殊字符 声调 语法 效果 语法 效果 语法 效果 \bar{x} \acute{\eta} \check{\alpha} \grave{\eta} \breve{a} \ddot{y} ...