1. 程式人生 > >計蒜課/UCloud 的安全秘鑰(hash)

計蒜課/UCloud 的安全秘鑰(hash)

con amp name ref cdc 代碼 ++ splay stream

題目鏈接:https://nanti.jisuanke.com/t/15768

題意:中文題誒~

思路:直接hash就好了,當時zz了沒想到...

代碼:

技術分享
 1 #include <iostream>
 2 #include <stdio.h>
 3 #define ll long long
 4 using namespace std;
 5 
 6 const int MAXN = 1e5;
 7 ll a[MAXN] = {1};
 8 ll w[MAXN];
 9 
10 int main(void){
11     ll n, m, k, x;
12     scanf("
%lld", &n); 13 for(int i = 1; i <= n; i ++){ 14 w[i] = w[i-1] * 233 + 17; 15 } 16 for(int i = 1; i <= n; i ++){ 17 cin >> x; 18 a[i] = a[i-1] + w[x]; 19 } 20 scanf("%lld", &m); 21 while(m--){ 22 ll ans = 0, cnt = 0; 23 cin >> k;
24 for(int i = 0; i < k; i++){ 25 cin >> x; 26 cnt += w[x]; 27 } 28 for(int i=k; i<=n; i++){ 29 if(a[i] - a[i-k] == cnt) ans ++; 30 } 31 printf("%lld\n", ans); 32 } 33 return 0; 34 }
View Code

計蒜課/UCloud 的安全秘鑰(hash)