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

每次知道最小值之后,怎么知道需要修改的位置呢
直接从每种数维护的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. CF 551E. GukiZ and GukiZiana [分块 二分]

    GukiZ and GukiZiana 题意: 区间加 给出$y$查询$a_i=a_j=y$的$j-i$最大值 一开始以为和论文CC题一样...然后发现他带修改并且是给定了值 这样就更简单了.... ...

  2. 关于WebApi 跨域问题的解决的方式

    最近在做WebApi 进行开发的时候 一直会遇到跨域方面的问题那么如何进行跨域问题其实非常的简单. 1.一直在使用WebApi的时候总是遇到跨域的问题 那么 什么是跨域?跨域,指的是浏览器不能执行其他 ...

  3. Windows Server 2016-查询FSMO角色信息的三种方法

    FSMO操作主机角色有五种:林范围操作主机角色有两种,分别是 架构主机角色(Schema Master)和 域命名主机角色(Domain Naming Master):及域范围操作主机角色三种,分别是 ...

  4. .35-浅析webpack源码之babel-loader入口文件路径读取

    在处理./input.js入口文件时,在类型判断被分为普通文件,所以走的文件事件流,最后拼接得到文件的绝对路径. 但是对应"babel-loader"这个字符串,在如下正则中被判定 ...

  5. header 头各种类型文件下载

    function down_file($url,$type='application/zip'){     header("Cache-Control: public");     ...

  6. C. Vasya and String

    原题链接 C. Vasya and String High school student Vasya got a string of length n as a birthday present. T ...

  7. POJ - 1860 Bellman-Ford判正环

    心累,陕西邀请赛学校不支持,可能要自费了.. 思路:套用Bellman-Ford判断负环的思路,把大于改成小于即可判定是否存在从源点能到达的正环.如果存在正环,那么完全多跑几次正环就可以把钱增加到足够 ...

  8. dll和lib(包括静态链接库和与dll同时生成的lib)

    转:http://blog.csdn.net/galaxy_li/article/details/7411956 1:神马是Dll和Lib,神马是静态链接和动态链接 大家都懂的,DLL就是动态链接库, ...

  9. 关联规则—频繁项集Apriori算法

    频繁模式和对应的关联或相关规则在一定程度上刻画了属性条件与类标号之间的有趣联系,因此将关联规则挖掘用于分类也会产生比较好的效果.关联规则就是在给定训练项集上频繁出现的项集与项集之间的一种紧密的联系.其 ...

  10. PHPstudy端口占用的问题

    phpStudy很多同学下好了 用localhost可能不能读取到WWW目录下的文件,这个是因为端口被占用,打开其他选项菜单 =>打开配置文件=>httpd-conf=>修改端口号如 ...