Codeforces Round #215 (Div. 2) C. Sereja and Algorithm
2013-11-28 22:47
453 查看
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main(){ string s ; cin >>s; int m; cin >>m; vector<int> l(m),r(m); for(int i = 0 ; i < m ; ++ i ) cin >> l[i]>>r[i]; int n = s.length(); vector<int> x(n+1,0),y(n+1,0),z(n+1,0); for(int i = 0; i < n; ++ i){ x[i+1] =x[i]; y[i+1] = y[i]; z[i+1] = z[i]; if(s[i] == 'x') x[i+1]++; else if(s[i] == 'y') y[i+1]++; else z[i+1]++; } for(int i = 0 ; i < m ; ++ i){ if(r[i]-l[i]+1 < 3) cout<<"YES"<<endl; else{ vector<int> num(3,0); num[0] = x[r[i]]-x[l[i]-1]; num[1] = y[r[i]]-y[l[i]-1]; num[2] = z[r[i]]-z[l[i]-1]; sort(num.begin(),num.end()); if((num[0] == num[1] && num[1] == num[2])|| (num[2]-num[1] == 1 && num[1] == num[0]) || (num[2]-num[1] == 0 && num[1] - num[0] == 1)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0; }
相关文章推荐
- Codeforces Round #215_div2_C. Sereja and Algorithm
- Codeforces Round #215 (Div. 1) C. Sereja and the Arrangement of Numbers(欧拉图)
- Codeforces Round #235 (Div. 2)B. Sereja and Contests
- CodeForces Round 223 Div 2 C Sereja and Prefixes
- Codeforces Round #215 (Div. 2) -B. Sereja and Suffixes
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #243 (Div. 2)——Sereja and Table
- CodeForces Round 213 Div 2 E Sereja and Brackets 线段树
- Codeforces Round #292 (Div. 2) -- C. Drazil and Factorial
- Codeforces Round #129 (Div. 1) A Little Elephant and Interval
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads (树形dp,lca)★ ★ ★
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
- Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) -- C. A and B and Team Training
- Codeforces Round #330 (Div. 1) A. Warrior and Archer
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution(STL乱搞)
- Codeforces Round #206 (Div. 2) E-Vasya and Beautiful Arrays