fork(2) download
  1. /**
  2.  * Dont raise your voice, improve your argument.
  3.  * --Desmond Tutu
  4.  */
  5.  
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. typedef unsigned int uint;
  9. typedef long long ll;
  10.  
  11. int main() {
  12. int n, q;
  13. n = 100000, q = 100000;
  14. //cin>>n>>q;
  15. vector<int> a(n);
  16. vector<char> s(q);
  17. vector<int> x(q);
  18.  
  19. for(auto &c : a)
  20. c = 1;
  21. //cin>>c;
  22.  
  23.  
  24. for(int i=0; i<q; i++) {
  25. string str;
  26. //cin>>str>>x[i];
  27. str = i % 2 == 0 ? ">" : "<";
  28. x[i] = i % 2 == 0 ? -i : i;
  29. s[i]=str[0];
  30. }
  31.  
  32. for(int i=0; i<n; i++) {
  33. if(a[i]==0)
  34. continue;
  35.  
  36. int la=abs(a[i]);
  37. int j;
  38. int flip=0;
  39. for(j=q-1; j>=0; j--) {
  40. if(abs(x[j])<la) {
  41. if(s[j]=='>') {
  42. a[i]=-abs(a[i]);
  43. } else {
  44. a[i]=abs(a[i]);
  45. }
  46. //cout<<"set a[i] at j="<<j<<" to a[i]="<<a[i]<<endl;
  47. j++;
  48. break;
  49. } else if(abs(x[j])==la) {
  50. if(s[j]=='<' && x[j]>0) {
  51. a[i]=abs(a[i]);
  52. j++;
  53. break;
  54. } else if(s[j]=='>' && x[j]<0) {
  55. a[i]=-abs(a[i]);
  56. j++;
  57. break;
  58. }
  59. } else {
  60. if(s[j]=='<' && x[j]>0)
  61. flip++;
  62. else if(s[j]=='>' && x[j]<0)
  63. flip++;
  64. }
  65. }
  66. //cout<<"i="<<i<<" j="<<j<<" flip="<<flip<<endl;
  67. if(flip%2==1)
  68. a[i]=-a[i];
  69.  
  70. /*
  71.   for(; j<q; j++) {
  72.   if( ((s[j]=='<') && (a[i]<x[j])) || ((s[j]=='>') && (a[i]>x[j]) )) {
  73. //cout<<"flip a[i], i="<<i<< " a[i]="<<a[i]<<endl;
  74.   a[i]=-a[i];
  75.   }
  76.   }
  77. */
  78. }
  79.  
  80. for(int i=0; i<n; i++)
  81. cout<<a[i]<<" ";
  82. cout<<endl;
  83.  
  84.  
  85. }
  86.  
Time limit exceeded #stdin #stdout 5s 16024KB
stdin
Standard input is empty
stdout
Standard output is empty