#define int long longconstint maxn =2e5+10;int a[maxn];voidsolve(){int n;cin>>n;int ans =0;int flagz =0;for(int i =1; i <= n;++i){int x;cin>>x;a[i]= x;if(x==0) flagz =1;}int right =0,left =0;if(flagz==0) cout<<0<<'\n';else{for(int i = n; i >1;--i){if(a[i]==0){ right = i+1;break;}}for(int i =1; i <= n;++i){if(a[i]==0){left = i-1;break;}}cout<<right-left<<'\n';}}signedmain(){std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);int t;cin>>t;for(int i =0; i < t;++i){solve();}}
#define int long longconstint maxn =1e5+10;vector<int> row[maxn];
vector<int> col[maxn];intcount(vector<int>&color){sort(color.begin(),color.end());int sum =0;int sz = color.size();for(int i =1; i < sz;++i){sum+=color[i];}int n = sz-1;int ans =0;for(int i =0; i < sz-1;++i){ans +=(sum-(n*color[i]));sum -= color[i+1];n--;}return ans;}signedmain(){std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);int n,m;cin>>n>>m;for(int i =1; i <=n ;++i){for(int j =1; j <=m ;++j){int x;cin>>x;row[x].push_back(i);col[x].push_back(j);}}int ans =0;for(int i =1; i <=100000;++i){ans+=(count(row[i])+count(col[i]));}cout<<ans;
#define int long longconstint maxn =1e6+10;inlinevoidsolve(){int n, c;cin >> n >> c;vector<int>sum(c+1);vector<int>cnt(c+1);int flago =0;for(int i =1; i <= n;++i){int x;cin >> x;if(x ==1) flago =1;cnt[x]++;}if(!flago){cout <<"NO"<<'\n';return;}for(int i =1; i <= c;++i){sum[i]= sum[i -1]+ cnt[i];}for(int i =1; i <= c;++i){// a[i]是选定的某个数if(!cnt[i])continue;int num = c / i;// num是所有合法的倍数for(int j =2; j <= num;++j){// j是倍数int right =min(c, i * j + i -1);int left = i * j;if(sum[right]- sum[left -1]>0&& cnt[j]==0){cout <<"NO"<<'\n';return;}}}cout <<"YES"<<'\n';}signedmain(){std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);int t;cin >> t;for(int i =0; i < t;++i){solve();}}
A. Game
题目传送门
题目理解:一个人要过河,这个人不会游泳,只能走陆地,一旦碰水就死翘翘,但是现在给你一个bug,只要你给x个硬币,你就可以传送到ix块陆地上面,比如你在第5块土地上…
Problem - B - Codeforces 翻译:
给定一个由𝑛个正整数组成的数组𝑎,这些正整数从1到𝑛编号。我们称数组为整数,如果这个数组中的任意两个不一定不同的数字𝑥和𝑦,&…