#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();}}
Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics) 题解
A. Game思路只能跳一次!!!!从左和从右开始找到第一个0,然后相减+2(从0回到上一格的1陆地)即可经验教训无AC代码#define int long longconst int maxn = 2e5 + 10;int a[maxn];void solve(){ int n;cin>>n; int ans = 0; int flagz = 0; for (int i = 1; i <= n; ++i) {