fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N,M;
  6. cin >> N;
  7. vector<int> A(N);
  8. map<int,int> C;
  9. for(int i =0; i < N; i++) {
  10. cin >> A[i];
  11. C[A[i]] +=1;}
  12. if(C.size() == 1) {cout << "0\n"; return 0;}
  13. cin >> M;
  14. for(int i =0; i < M; i++) {
  15. int x,y;
  16. cin >> x >> y;
  17. x--;
  18. C[A[x]] -=1;
  19. C[y] +=1;
  20. A[x] =y;
  21. if(C[y] == N) {cout << i+1 << "\n"; return 0;}
  22. }
  23. cout << "-1\n";
  24. return 0;}
Success #stdin #stdout 0s 3484KB
stdin
3
4 3 7
4
1 5
2 7
1 7
3 3
stdout
3