Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define MAXN 131072*8
  3. using namespace std;
  4. vector< pair<int,int> >v[MAXN];
  5. string s;
  6. int cnt=1,used[MAXN],arr[MAXN],m[MAXN];
  7. int main()
  8. {
  9. int x,n,i,j,tek=0,id=0,ans=0;
  10. cin>>n;
  11. for(i=0;i<n;i++)
  12. {
  13. cin>>s;
  14. x=0;
  15. for(j=1;j<s.size();j++)
  16. {
  17. x*=10;
  18. x+=s[j]-'0';
  19. }
  20. if(!used[x])
  21. {
  22. used[x]=cnt;
  23. v[cnt++].push_back({s[0]=='s' ? 1 : -1 ,i+1});
  24. }
  25. else
  26. {
  27. v[used[x]].push_back({s[0]=='s' ? 1 : -1 ,i+1});
  28. }
  29. }
  30. memset(used,0,sizeof(used));
  31. for(i=1;i<cnt;i++)
  32. {
  33. tek=0;
  34. //cout<<i<<" : ";
  35. for(j=0;j<v[i].size();j++)
  36. {
  37. //cout<<v[i][j].second<<" ";
  38. tek+=v[i][j].first;
  39. m[i]=min(tek,m[i]);
  40. }//cout<<endl;
  41. if(tek!=0)used[i]=true;
  42. }
  43. for(i=1;i<cnt;i++)
  44. {
  45. if(used[i])continue;
  46. tek=0;
  47. for(j=0;j<v[i].size();j++)
  48. {
  49. tek+=v[i][j].first;
  50. if(tek==m[i])
  51. {
  52. arr[v[i][j].second]++;
  53. if(j==v[i].size()-1)
  54. {
  55. arr[n+2]--;
  56. arr[0]++;
  57. arr[v[i][0].second]--;
  58. }else arr[v[i][j+1].second]--;
  59. }
  60. }
  61. }
  62. tek=0;
  63. for(i=0;i<=n;i++)
  64. {
  65. tek+=arr[i];
  66. if(tek>ans)
  67. {
  68. ans=tek;
  69. id=i;
  70. }
  71. }
  72. if(id+1==n+1)
  73. id=1;
  74. cout<<id+1<<" "<<ans<<endl;
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement