Advertisement
maritzalapa

CODEFORCES - 316 DIV2 - Replacement

Aug 28th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define f(i,x,y) for(int i = x; i < y; i++)
  3. #define clr(A, x) memset(A, x, sizeof A)
  4. #define N 100005
  5.  
  6. using namespace std;
  7.  
  8. int n, m, pos, tot=0, act=0;
  9. string str;
  10. char c;
  11.  
  12. int main(){
  13.     cin>>n>>m;
  14.     cin>>str;
  15.  
  16.     //Total inicial
  17.     f(i,0,n){
  18.         if(str[i]=='.') act++;
  19.         else{
  20.             if(act) tot+=(act-1);
  21.             act=0;
  22.         }
  23.     }
  24.     if(act) tot+=(act-1);
  25.    
  26.     //Depende solo de los costados, máximo las respuestas entre uno y otro caso varían en 2
  27.     f(i,0,m){
  28.         cin>>pos>>c;
  29.         if( c==str[pos-1] || ( isalpha(c) && isalpha(str[pos-1]) ) ) cout<<tot<<endl;
  30.         else{
  31.             if(c=='.'){
  32.                 if(pos>1 && str[pos-2]=='.') tot++;
  33.                 if(pos<n && str[pos]=='.') tot++;
  34.             }
  35.             else{
  36.                 if(pos>1 && str[pos-2]=='.') tot--;
  37.                 if(pos<n && str[pos]=='.') tot--;              
  38.             }
  39.             cout<<tot<<endl;
  40.             str[pos-1]=c;
  41.         }
  42.     }  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement