[contest:364982]
A. Fafa and his Company
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, cnt = 0;
cin >> n;
for(int i=1; i<n; i++){
if((n-i)%i == 0) cnt++;
}
cout << cnt;
}
B. Simple XML
#include<bits/stdc++.h>
using namespace std;
int main(){
string in;
cin >> in;
int l=in.length();
vector<string> v;
for(int i=0; i<l-3; i++){
if(in[i+1]=='/'){
v.push_back(in.substr(i,4));
i+=3;
}else{
v.push_back(in.substr(i,3));
i+=2;
}
}
int s = v.size(), sp = 0;
for(int i=0; i<s; i++){
if(v[i][1]=='/') sp--;
for(int j=0;j<sp*2; j++){
cout << ' ';
}
cout << v[i] << '\n';
if(v[i][1]!='/'){
sp++;
}
}
}
C. Good String
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
string s;
cin >> s;
int final = 1e9+10, n = s.size();
for(char i='0'; i<='9'; i++){
for(char j='0'; j<='9'; j++){
int x = 1, cnt = 0;
for(int k=0; k<n; k++){
if(x and s[k] == i) cnt += (i == j),x^=1;
else if(!x and s[k] == j) cnt++, x^=1, cnt += (i != j);
}
final = min(final, n-cnt);
}
}
cout << final << '\n';
}
}
D. Three-dimensional Turtle Super Computer
#include<bits/stdc++.h>
using namespace std;
template<typename... Args>
void dbg(Args... args){ ((cout << args << " "), ...);}
const int N = 110;
char t[N][N][N];
char f[N][N][N];
int main(){
int n, m, k;
cin >> n >> m >> k;
for(int x = 1; x <= n; ++x)
for(int y = 1; y <= m; ++y)
for(int z = 1; z <= k; ++z){
cin >> t[x][y][z]; t[x][y][z] -= '0';
}
for(int x = 1; x <= n; ++x)
for(int y = 1; y <= m; ++y)
for(int z = 1; z <= k; ++z){
if(!t[x][y][z]) continue;
bool tmp[3][3][3][3] {};
bool ok[3][3][3] {};
tmp[0][0][0][0] = 1, tmp[0][0][0][1] = 1, tmp[0][0][0][2] = 1;
ok[0][0][0] = 1;
for(int o = 0; o < 3; ++o)
for(int p = 0; p < 3; ++p)
for(int q = 0; q < 3; ++q)
if(t[x+o][y+p][z+q]){
tmp[o][p][q][0] |= ((o>0) ? ok[o-1][p][q] : false);
tmp[o][p][q][1] |= ((p>0) ? ok[o][p-1][q] : false);
tmp[o][p][q][2] |= ((q>0) ? ok[o][p][q-1] : false);
int good = tmp[o][p][q][0] +
tmp[o][p][q][1] +
tmp[o][p][q][2];
ok[o][p][q] = good;
if(good == 1){
if(o==0&&p==1&&q==0||
o==0&&p==0&&q==1||
o==1&&p==0&&q==0||
o==0&&p==0&&q==0) continue;
if(o>0 and ok[o-1][p][q]) f[x+o-1][y+p][z+q] = 1;
if(p>0 and ok[o][p-1][q]) f[x+o][y+p-1][z+q] = 1;
if(q>0 and ok[o][p][q-1]) f[x+o][y+p][z+q-1] = 1;
}
}
}
int cnt = 0;
for(int x = 1; x <= n; ++x)
for(int y = 1; y <= m; ++y)
for(int z = 1; z <= k; ++z){
if(f[x][y][z] == 1) ++cnt;
}
dbg(cnt);
}
E. Need For Brake
#include <bits/stdc++.h>
#define sz 100005
using namespace std;
struct node{
char s[100];
int a;
}e[sz];
bool cmp(node x,node y){
if(x.a!=y.a){
return x.a<y.a;
}
else {
if(strcmp(x.s,y.s)<0)
return 1;
else return 0;
}
}
bool cmp1(int x,int y){
return x<y;
}
int main(){
int n,m,i,j,b[sz];
scanf("%d",&n);
for(i=0;i<n;i++){
cin>>e[i].s>>e[i].a;
}
cin>>m;
memset(b,0,sizeof(b));
for(i=0;i<m;i++){
cin>>b[i];
b[i]*=2;
}
sort(e,e+n,cmp);
sort(b,b+n,cmp1);
char str[100];
cin>>str;
int id;
int ans;
for(i=0;i<n;i++){
if((ans=strcmp(e[i].s,str))==0){
e[i].a=2*e[i].a+1;
}
else{
if(ans>0){
e[i].a*=2;
}
else e[i].a=e[i].a*2+1;
}
}
sort(e,e+n,cmp);
for(i=0;i<n;i++){
if(strcmp(e[i].s,str)==0){
id=i;
break;
}
}
//find high
int sum=e[id].a+b[n-1];
int cnt=0;
j=0;
for(i=n-1;i>=0;i--){
if(i==id)continue;
for(;j<n-1;){
if(e[i].a+b[j]<sum){j++;break;}
else {cnt++;break;}
}
}
cout<<cnt+1<<" ";
sum=e[id].a+b[0];
j=n-1;
cnt=0;
for(i=0;i<n;i++){
if(i==id)continue;
for(;j>=0;){
if(e[i].a+b[j]<sum)break;
else {
j--;
cnt++;
break;
}
}
}
cout << cnt+1 << '\n';
}
F. Powerful array
#include<bits/stdc++.h>
using namespace std;
int fre[1000001],ar[200001];
long long ans[200001];
long long power=0;
int len;
struct query{
int l;
int r;
int i;
};
query Q[200001];
bool comp(query a,query b){
if(a.l/len!=b.l/len)
return a.l/len<b.l/len;
return a.r<b.r;
}
void add(int pos){
long long cnt=fre[ar[pos]];
fre[ar[pos]]++;
power-=(cnt*cnt)*ar[pos],cnt++;
power+=(cnt*cnt)*ar[pos];
}
void remove(int pos){
long long cnt=fre[ar[pos]];
fre[ar[pos]]--;
power-=(cnt*cnt)*ar[pos],cnt--;
power+=(cnt*cnt)*ar[pos];
}
int main(){
int n, q;
cin >> n >> q;
len = sqrt(n);
for(int i=0;i<n;i++) cin >> ar[i];
for(int i=0;i<q;i++) {
cin >> Q[i].l >> Q[i].r;
Q[i].i=i;
Q[i].l--;
Q[i].r--;
}
sort(Q,Q+q,comp);
int ML=0, MR=-1;
for(int i=0;i<q;i++){
int L=Q[i].l;
int R=Q[i].r;
while(ML>L) ML--, add(ML);
while(MR<R) MR++, add(MR);
while(ML<L) remove(ML), ML++;
while(MR>R) remove(MR), MR--;
ans[Q[i].i] = power;
}
for(int i=0;i<q;i++) cout << ans[i] << '\n';
}