位运算
题目链接:https://codeforces.com/contest/1922/problem/B
题意
有一个正整数数组
数据范围
题解
由三角形的性质知,两边的和大于第三边,而对于本题中将
Code:
#include< bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
int t,n,a[300010],pre[300010];
map< int,int> mp;
int C_2(int n){
return n*(n-1)/(2LL);
}
int C_3(int n){
return n*(n-1)*(n-2)/(6LL);
}
signed main(){
std::ios::sync_with_stdio(false);cin.tie(nullptr);
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++)
cin >> a[i], mp[a[i]]++;
int suf=0, sum=0, ans=0;
for(auto it:mp){
if(it.second >= 2)ans += C_3(it.second) + C_2(it.second)* sum;
sum += it.second;
}
cout << ans << endl;
mp.clear();
}
return 0;
}
题目链接:https://ac.nowcoder.com/acm/contest/80743/E
题意
第一行输入正整数n和k,代表字符串的长度和需要选择的子序列的长度,第二行输入一个长度为n的数字字符串,求所有子序列构成的十进制数之和(允许含有前导零)并对答案进行取模(
当n=4,k=3时,5022可拆分成 502 + 502 + 522 + 022 = 1548
数据范围
题解
求的是十进制数,我们依旧从拆位算贡献的角度出发,如果当前位的值为x,后面还有cnt位未知,那么对于一个子序列单次的贡献显然是Code:
#include#define int long long #define endl '\n' #define INF 1e15 using namespace std; typedef pair pii; char s[1010]; const int p = 1e9 + 7; int jc[100010], njc[100010], inv[100010]; int C(int x, int y) { return 1LL * jc[x] * njc[y] % p * njc[x - y] % p; } int power_mod(int a, int b, int mod) { int res = 1; a = a % mod; while (b) { if (b & 1) res = (res * a) % mod; b /= 2; a = (a * a) % mod; } return res; } signed main(){ std::ios::sync_with_stdio(false);cin.tie(0); for (int i = 0; i < 2; i++) jc[i] = njc[i] = inv[i] = 1; for (int i = 2; i <= 100001; i++){ jc[i] = 1LL * jc[i - 1] * i % p; inv[i] = 1LL * inv[p % i] * (p - p / i) % p; njc[i] = 1LL * njc[i - 1] * inv[i] % p; } int n, k; cin >> n >> k; cin >> s + 1; int ans = 0; for (int i = 1; i <= k;i++) for (int j = i; j <= n - k + i;j++) ans = (ans + ((((s[j] - '0') * (C(n - j, k - i) % p) % p) * (C(j - 1, i - 1) % p) % p) * power_mod(10, k - i, p)) % p) % p; cout << ans << endl; return 0; }
题目链接:https://codeforces.com/contest/1968/problem/F
题意
给定一个非负整数的数组,如果对某个区间进行若干次的分割,使得每一个数都恰好落在一个段内,且这若干个段的异或和(XOR)相等,则称这个区间为“好区间”。给出q次询问,每次输入l,r,请问区间[l,r]是否为“好区间”.
例如,区间[1,1,2,3,0]可分为[1],[1],[2,3,0]三段,因为
数据范围
思路分析
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.


