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

每次知道最小值之后,怎么知道需要修改的位置呢
直接从每种数维护的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. MySQL索引之B+树

    MySQL索引大都存储在B+树中,除此还有R树和hash索引.B+树的基础还是B树. B树由2部分组成,节点和索引.下面将构建一个B树,每个节点存2个数据,每个节点有前,中,后三个索引.插入数字的顺序 ...

  2. HDU 6181 Two Paths

    这是一道次短路的题 但是本题有两个坑 注意边权的范围,一定要在所有与距离有关的地方开 long long 本题所求的并不是次短路,而是与最短路不同的最短的路径,如果最短路不止一条,那么就输出最短路的长 ...

  3. bzoj 2618: [Cqoi2006]凸多边形 [半平面交]

    2618: [Cqoi2006]凸多边形 半平面交 注意一开始多边形边界不要太大... #include <iostream> #include <cstdio> #inclu ...

  4. 走进JavaScript——重拾函数

    创建函数 通过构造器的方式来创建函数,最后一个参数为函数体其他为形参 new Function('a','b','alert(a)') /* function anonymous(a,b) { ale ...

  5. Mysql查询某字段值重复的数据

    查询user表中,user_name字段值重复的数据及重复次数 select user_name,count(*) as count from user group by user_name havi ...

  6. Docker Centos6 下建立 Docker 桥接网络

    cd /etc/sysconfig/network-scripts/; cp ifcfg-eth0  ifcfg-br0 vi ifcfg-eth0 //增加BRIDGE=br0,删除IPADDR,N ...

  7. Spring Boot - Font Awesome OTS parsing error: Failed to convert 字体加载失败

    字体文件,加载不出来 解决方案  一 问题是Maven正在过滤字体文件并破坏它们. <resource> <directory>${project.basedir}/src/m ...

  8. C#委托与事件--简单笔记

    委托 简单记录点东西 适合似懂非懂的朋友看看 委托类型用来定义和响应应用程序中的回调. 借此可以设计各种有面向对象特性的代码模式.下面要说的事件在我看来就是委托的一种实现,再深一步讲,利用委托加事件, ...

  9. js中boolean类型的理解

    <html> <head> <script type="text/javascript"> var x="12"; aler ...

  10. 手把手教你树莓派实现简易室内监控系统(A)

    第一次写博文,有很多疏漏之处,然后受逼乎影响较深,希望大家多多包涵! _______________________________________________分割线是这样画的吧_________ ...