fork(1) download
  1. /*input
  2. 4 2
  3. 1 2 3 3
  4. 1 2 1
  5. 2 1
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. const int mod=1e9 + 7;
  10. #define int long long
  11. const int inf=1e18;
  12. const int N=1e6 + 100;
  13. #define pii pair<int, int>
  14. #define f first
  15. #define s second
  16. #define mp make_pair
  17. #define FOR(i, n) for(int i=1;i<=n;i++)
  18. #define TRACE(x) cerr << #x << " = " << x << endl
  19. //Trace prints the name of the variable and the value.
  20. int n, m, arr[N];
  21. signed main()
  22. {
  23. ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  24. //freopen("input.txt","r",stdin);freopen("output0.txt","w",stdout);
  25. cin>>n>>m;
  26. assert(n<=1e6);assert(m<=2e5);
  27. arr[0]=inf;set<int> start;
  28. for(int i=1;i<=n;i++) {cin>>arr[i];assert(arr[i]<=1e6);
  29. if(arr[i]%arr[i-1]!=0) start.insert(i);
  30. }
  31. arr[n+1]=mod;
  32. while(m--)
  33. {
  34. int t;cin>>t;assert(t==1||t==2);
  35. if(t==1)
  36. {int ind, val;cin>>ind>>val;assert(ind<=n);assert(val<=1e6);
  37. arr[ind]=val;
  38. if(arr[ind]%arr[ind-1]!=0) start.insert(ind);
  39. else start.erase(ind);
  40. if(arr[ind+1]%arr[ind]!=0) start.insert(ind+1);
  41. else start.erase(ind+1);}
  42. else{
  43. int ind;cin>>ind;
  44. set<int>::iterator it=start.upper_bound(ind);it--;
  45. cout<<(*it)<<endl;
  46. }
  47. }
  48. }
Success #stdin #stdout 0s 4584KB
stdin
Standard input is empty
stdout
Standard output is empty