ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客挑战赛46 D

2020-12-14 21:02:25  阅读:189  来源: 互联网

标签:cnt const 46 牛客 int hash1 挑战赛 include define


include

include

include

include

include

include

include

include

include

include

include

include

//#include

include

include

include<unordered_map>

pragma GCC diagnostic error "-std=c++11"

pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)

pragma GCC target("avx","sse2")

define up(i,a,b) for(int i=a;i<b;i++)

define dw(i,a,b) for(int i=a;i>b;i--)

define upd(i,a,b) for(int i=a;i<=b;i++)

define dwd(i,a,b) for(int i=a;i>=b;i--)

//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
char ch = getchar(); ll x = 0, f = 1;
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
typedef pair<int, int> pir;

define lson l,mid,root<<1

define rson mid+1,r,root<<1|1

define lrt root<<1

define rrt root<<1|1

const int N = 1e6 + 10;
const ull base1 = 1e9 + 7;
const ull base2 = 23333333;
ull hash1[N], hash2[N];
ull cnt[N];
int n, k;
void init() {
hash1[0] = 1; hash2[0] = 1;
upd(i, 1, 1e6) {
hash1[i] = hash1[i - 1] * base1;
hash2[i] = hash2[i - 1] * base2;
}
}
unordered_map<ull, int>mp1,mp2;
int main() {
n = read(), k = read();
init();
mp1[0] = mp2[0] = 1;
ull tmp1 = 0, tmp2 = 0; int a;
ll ans = 0;
upd(i, 1, n) {
a = read();
tmp1 -= cnt[a] * hash1[a];
tmp2 -= cnt[a] * hash2[a];
cnt[a]++; cnt[a] %= k;
tmp1 += cnt[a] * hash1[a];
tmp2 += cnt[a] * hash2[a];
if (mp1[tmp1] && mp2[tmp2]) {
ans += mp1[tmp1];
}
mp1[tmp1]++; mp2[tmp2]++;
}
printf("%lld\n", ans);
return 0;
}

标签:cnt,const,46,牛客,int,hash1,挑战赛,include,define
来源: https://www.cnblogs.com/LORDXX/p/14135659.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有