fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef pair<int,int> pii;
  4. typedef pair<long long,long long> pll;
  5. typedef vector<int> vi;
  6. typedef vector<long long> vll;
  7. typedef vector<pii> vpii;
  8. typedef vector<pll> vpll;
  9. #define f first
  10. #define s second
  11. #define mp make_pair
  12. #define pb push_back
  13. #define MOD 1000000007
  14. #define ll long long
  15. int GCD(int a, int b)
  16. {
  17. return b? GCD(b,a%b) : a;
  18. }
  19. struct sort_pred
  20. {
  21. bool operator()(const pair<int,int> &left, const pair<int,int> &right)
  22. {
  23. return left.second < right.second;
  24. }
  25. };
  26. long long POW(long long Base, long long Exp)
  27. {
  28. long long y,ret=1;
  29. y=Base;
  30. while(Exp)
  31. {
  32. if(Exp&1)
  33. ret=(ret*y);
  34. y = (y*y);
  35. Exp/=2;
  36. }
  37. return ret;
  38. }
  39. //vi num,val,p;
  40. //set<int> A,B,tmp;
  41. //vll ans;
  42. //vpll A,Rec,Rec2;
  43. int clusters=1;
  44. int dx[4]={1,-1,0,0};
  45. int dy[4]={0,0,1,-1};
  46.  
  47. //int Mark[100007];
  48. vector < pair < pii, long long > > Jobs;
  49.  
  50. set<pair<int,int> > S;
  51. vector<pair<int,int> > in;
  52. vector<pair<long double,int> > v,d,ans;
  53. #define PI 3.14159265358979323846
  54. bool fn(const pair<long double,int>& L, const pair<long double,int>& R)
  55. {
  56. if(L.first == R.first)
  57. {
  58. return L.second > R.second;
  59. }
  60. else
  61. {
  62. return L.first < R.first;
  63. }
  64. }
  65. vector<int> A,B;
  66. int Mark[300007];
  67. #define MAX 2000007
  68. #define LIM 1000000
  69. ll x[MAX], y[MAX], cx[MAX], cy[MAX];
  70. string str;
  71. int main()
  72. {
  73. int n, m, tx, ty, i;
  74. cin>>n>>m;
  75. long long Ans = 0;
  76. for(i=0; i<n; i++)
  77. {
  78. scanf("%d %d", &tx, &ty);
  79. x[tx+LIM] += tx;
  80. y[ty+LIM] += ty;
  81. cx[tx+LIM]++;
  82. cy[ty+LIM]++;
  83. }
  84. cin>>str;
  85.  
  86. for(i=1; i<=2000000; i++)
  87. {
  88. x[i] += x[i-1];
  89. y[i] += y[i-1];
  90. cx[i] += cx[i-1];
  91. cy[i] += cy[i-1];
  92. }
  93. tx=ty=0;
  94. for(i=0; i<m; i++)
  95. {
  96. if (str[i] == 'D')
  97. ty--;
  98. else if (str[i] == 'U')
  99. ty++;
  100. else if (str[i] == 'L')
  101. tx--;
  102. else
  103. tx++;
  104.  
  105. Ans = (cx[tx + LIM] * tx - x[tx + LIM] + x[2000000] - x[tx + LIM] - (cx[2000000] - cx[tx + LIM]) * tx);
  106. Ans += (cy[ty + LIM] * ty - y[ty + LIM] + y[2000000] - y[ty + LIM] - (cy[2000000] - cy[ty + LIM]) * ty);
  107. printf("%lld\n",Ans);
  108. }
  109. return 0;
  110. }
Success #stdin #stdout 0.06s 67136KB
stdin
2 3
1 2
0 1
RDL
stdout
4
6
6