给你一个数组 a1,a2…an 。请计算有多少个图元 (i,j,k,l)符合以下条件:
·
· a
The first line contains a single integer
The first line of each test case contains a single integer
The second line of each test case contains n integers a
It's guaranteed that the sum of n in one test doesn't exceed 3000.
For each test case, print the number of described tuples.
题目链接:https://codeforces.com/contest/1400/problem/D
哈希一下其实可以更快,但是数据量不大,n方解决即可;
AC代码:
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
#define int long long
const int Mod=998244353;
void save_the_people(){
int n,ans{0};
cin>>n;
vector<int> a(n);
for(int i{0};i<n;i++){
cin>>a[i];
a[i]--;
}
vector<int> c1(n),c2(n);
for(int i{0};i<n;i++){
fill(c1.begin(), c1.end(),0);
fill(c2.begin(), c2.end(),0);
for(int l{i+1};l<n;l++){
c2[a[l]]++;
}
int res{0};
for(int k{i+1};k<n;k++){
res-=c1[a[k]];
c2[a[k]]--;
if(a[i]==a[k])
ans+=res;
res+=c2[a[k]];
c1[a[k]]++;
}
}
cout<<ans<<"\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t{1};
cin>>t;
while(t--) {
save_the_people();
}
}
题目链接:https://codeforces.com/contest/1934/problem/D1
一道位运算的题,只要找出初始数n转为二进制后第一二个1的位置和目标数第一个1的位置的关系即可解决;
/***
* author: touirst
* created: now
***/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e9+5;
void save_the_newnew() {
ll n,m;
cin>>n>>m;
//cout<<n<<"\n";
//cout<<(n^m)<<"\n";
if((n^m)<n){cout<<1<<"\n"<<n<<" "<<m<<"\n";return;}
ll lim{0},bn{63},bm{63};
vector<int> a(65),b(65);
//cout<<n<<"\n";
while(!((n>>bn)&1)){
bn--;
}
//cout<<bn<<"\n";
bn--;
//cout<<bn<<"\n";
while(!((n>>bn)&1)){
bn--;
}
//cout<<bn<<"\n";
lim=(1ll<<(bn+1))-1;
//cout<<lim<<"\n";
while(!((m>>bm)&1)){
bm--;
}
if(lim==m){
cout<<1<<"\n"<<n<<" "<<m<<"\n";return;
}else if(lim<m||lim>=n){
cout<<"-1\n";return;
}else{
cout<<2<<"\n"<<n<<" "<<lim<<" "<<m<<"\n";
}
//cout<<bm<<"\n";
//cout<<((7>>0)&1)<<" "<<((7>>1)&1)<<" "<<((7>>2)&1);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int ttt{1};
cin>>ttt;
while(ttt--){
save_the_newnew();
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)