codeforces 190D Non-Secret Cypher 双指针
来源:互联网 发布:sql零基础视频教程 编辑:程序博客网 时间:2024/05/16 18:37
给定长度为n的数组a,给定k,问有多少个子数组,其中至少包含着有k个相同的数字
双指针经典题目,注意先要离散,然后注意m是1的情况
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <map>#define rep(i, j, k) for(int i = j; i <= k; i++)#define maxn 1000009#define ll long longusing namespace std;int n, m, a[maxn], c[maxn], now = 0, cnt = 0;int cunt[maxn];map <int, int> mp;ll ans = 0;int main (){cin >> n >> m;rep (i, 1, n)cin >> a[i], c[i] = a[i];sort (c + 1, c + 1 + n);c[0] = c[1] - 1;cnt = 0;rep (i, 1, n)if (c[i] != c[i - 1])mp[c[i]] = ++cnt;rep (i, 1, n)a[i] = mp[a[i]];//rep (i, 1, n) printf ("%d %d\n", i, a[i]);int r = 1;cunt[a[1]]++;if (m == 1)now++;rep (l, 1, n){while (now == 0 && r < n){r++;cunt[a[r]]++;if (cunt[a[r]] >= m)now++;}if (now)ans += 1LL * n - 1LL * r + 1LL;cunt[a[l]]--;if (cunt[a[l]] == m - 1)now--;}cout << ans << endl;}
0 0
- codeforces 190D Non-Secret Cypher 双指针
- Codeforces 190D Non-Secret Cypher
- CodeForces Round #120 (190D) - Non-Secret Cypher
- codeforces 190D Non-Secret Cypher(two pointers)
- Codeforces 190D Non-Secret Cypher【思维+RMQ+二分】
- D. Non-Secret Cypher
- CF 190D Non-Secret Cypher
- CF 190D. Non-Secret Cypher
- Codeforces Round #120 (Div. 2) / 190D Non-Secret Cypher (计数&two pointers)
- Codeforces Round #120(190D) Non-Secret Cypher(尺取法)
- cf 120 c,d,e STL Non-Secret Cypher Counter Attack
- codeforces 590D Top Secret Task(dp)
- Codeforces 590D Top Secret Task
- Codeforces #590D: Top Secret Task 题解
- 【CODEFORCES】 C. Hacking Cypher
- CodeForces 490C Hacking Cypher
- CodeForces 490C - Hacking Cypher
- codeforces 490C Hacking Cypher
- [初学 Unity]Graphics-04.Using Cameras && Using Lights && Fun with Lasers
- pat- Acute Stroke (30)
- 小回顾-数据类型的转换
- Maven项目不能发布到Tomcat问题
- linux中使用CST时间
- codeforces 190D Non-Secret Cypher 双指针
- thinkPHP查询操作
- 一篇很好的EDP入门介绍文章——了解AUX,PSR,ASSR 以及EDP版本的差异
- CSS浮动
- 看懂UML类图和时序图
- Effective Modern C++ 条款33 对需要std::forward的auto&&参数使用decltype
- android判断手势方向详解
- (转)作为一个新人,怎样学习嵌入式Linux?(韦东山)
- DatePicker、DatePickerDialog的使用