MAGCARI

zuma

Nov 8th, 2023
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[1000010];
  4. int main(){
  5.     int n,k,v,l,r,now,cnt;
  6.     bool raberd=false;
  7.     cin>>n>>k>>v;
  8.     for(int i=0;i<n;i++){
  9.         cin>>a[i];
  10.     }
  11.     l=k-1;
  12.     r=k;
  13.     now=v;
  14.     if(l>=0 && r<n && a[l]==v && a[r]==v){
  15.         // shoot in the middle
  16.         raberd=true;
  17.     }else if(r+1 < n && a[r] == v && a[r+1] == v){
  18.         // shoot in the left
  19.         raberd=true;
  20.     }else if(l-1>=0 && a[l] == v && a[l-1] == v){
  21.         // shoot in the right
  22.         raberd=true;
  23.     }
  24.     cnt=1;
  25.     while(raberd){
  26.         int tmpL = l, tmpR = r;
  27.         while(l>=0 && a[l]==now){
  28.             l--;
  29.             cnt++;
  30.         }
  31.         while(r<n && a[r]==now){
  32.             r++;
  33.             cnt++;
  34.         }
  35.         if(cnt<3){
  36.             raberd=false;
  37.             l = tmpL;
  38.             r = tmpR;
  39.             break;
  40.         }
  41.         cout << l << " " << r << endl;
  42.         if(l == -1 || r == n)
  43.             break;
  44.         now=a[l];
  45.         cnt=0;
  46.     }
  47.     if(l==-1&&r==n){
  48.         return 0;
  49.     }
  50.     for(int i=0;i<=l;i++){
  51.         cout<<a[i]<<" ";
  52.     }
  53.     if(r-l == 1)
  54.         cout << v << " ";
  55.     for(int i=r;i<n;i++){
  56.         cout<<a[i]<<" ";
  57.     }
  58.     return 0;
  59. }
  60. /*
  61. 1 3 1 4 4 1 1 5 5 5
  62.   ^           ^
  63. */
Advertisement
Add Comment
Please, Sign In to add comment