计蒜课/UCloud 的安全秘钥(hash)
题目链接: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 }
我就是我,颜色不一样的烟火 --- geloutingyu