fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MaxN=2e5;
  4. const int MaxA=2e5;
  5.  
  6. vector<int> pos[MaxA+1];
  7. int add[MaxA+1]={};
  8. int tag[MaxA+1];
  9.  
  10. int main() {
  11. int N, t, x;
  12. cin>>N;
  13. for(int n=1; n<=N; n++){
  14. cin>>t>>x;
  15. if(t==1){
  16. pos[x].push_back(n);
  17. }else{
  18. if(pos[x].empty()){
  19. cout<<-1;
  20. return 0;
  21. }
  22. }
  23. add[n]-=1;
  24. add[pos[x].back()]++;
  25. pos[x].pop_back();
  26. }
  27. //差分
  28. int ans=0;
  29. int now=0;
  30. for(int n=1; n<=N; n++){
  31. now+=add[n];
  32. ans=max(ans,now);
  33. }
  34. cout<<ans<<"\n";
  35. for(int n=1; n<=N; n+=1)
  36. if( -1<tag[n] )
  37. cout<<tag[n]<<" ";
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 9188KB
stdin
13
1 2
1 3
1 1
1 3
1 2
2 3
1 3
1 3
2 3
1 3
2 2
2 3
2 1
stdout
-1