gha890826

a048: 函数增减性

Apr 13th, 2018 (edited)
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int N,Q;
  8.     while(cin>>N>>Q)
  9.     {
  10.         bool type[N]={0};
  11.         for(int i=0;i<Q;i++)
  12.         {
  13.             int v,R,L,change;
  14.             cin>>v;
  15.             if(v==1)
  16.             {
  17.                 cin>>change;
  18.                 if(type[change-1])
  19.                     type[change-1]=0;
  20.                 else
  21.                     type[change-1]=1;
  22.             }
  23.             else
  24.             {
  25.                 bool ans=0;
  26.                 cin>>L>>R;
  27.                 for(int j=R;j>L;j--)
  28.                 {
  29.                     if(type[j-1])
  30.                     {
  31.                         if(ans==1)
  32.                             ans=0;
  33.                         else
  34.                             ans=1;
  35.                     }
  36.                 }
  37.                 cout<<ans<<endl;
  38.             }
  39.         }
  40.        
  41.     }
  42. }
Add Comment
Please, Sign In to add comment