Advertisement
Ritam_C

Codeforces Round 102 D

Jan 14th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1.     #include <bits/stdc++.h>
  2.     #define ll long long
  3.     #define ld long double
  4.     #define pb push_back
  5.     #define p_b pop_back
  6.     using namespace std;
  7.      
  8.     int main(){
  9.         ios_base::sync_with_stdio(false);
  10.         cin.tie(NULL);
  11.         int t;
  12.         cin >> t;
  13.         while(t--){
  14.             int n, m;
  15.             cin >> n >> m;
  16.             string s;
  17.             cin >> s;
  18.             for(int i = 0; i < m; i++){
  19.                 int x = 0;
  20.                 set<int> s1;
  21.                 s1.insert(0);
  22.                 int a, b;
  23.                 cin >> a >> b;
  24.                 for(int j = 0; j < a-1; j++){
  25.                     if(s[j] == '+'){
  26.                         x++;
  27.                     } else if(s[j] == '-'){
  28.                         x--;
  29.                     }
  30.      
  31.                     s1.insert(x);
  32.                 }
  33.      
  34.                 for(int j = b; j < s.length(); j++){
  35.                     if(s[j] == '+'){
  36.                         x++;
  37.                     } else if(s[j] == '-'){
  38.                         x--;
  39.                     }
  40.      
  41.                     s1.insert(x);
  42.                 }
  43.      
  44.                 cout << s1.size() << "\n";
  45.             }
  46.         }
  47.         return 0;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement