fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios::sync_with_stdio(false);
  3. #define ll long long int
  4. #define PI 3.14159265
  5. #define LIMIT 200000
  6. #define cos2(x) cos ( x * PI / 180.0 )
  7. #define sin2(x) sin ( x * PI / 180.0 )
  8. using namespace std;
  9.  
  10. int main() {
  11. int t;
  12. ll n, q;
  13. ll l, r;
  14.  
  15. cin >> t;
  16.  
  17. while(t--) {
  18. cin >> n >> q;
  19. char arr[n];
  20.  
  21. scanf("%s\n", &arr);
  22.  
  23. double cx[n], cy[n];
  24. cx[0] = cos2((arr[0]-'0') * 60);
  25. cy[0] = sin2((arr[0]-'0') * 60);
  26.  
  27. for (int i=1; i<n; i++) {
  28. int d = arr[i]-'0';
  29. cx[i] = cx[i-1] + cos2(d*60);
  30. cy[i] = cy[i-1] + sin2(d*60);
  31. }
  32.  
  33. while(q--) {
  34. double x = 0, y = 0;
  35. cin >> l >> r;
  36.  
  37. l -= 1;
  38. r -= 1;
  39.  
  40. if (l >= n || r >= n || l < 0 || r < 0) {
  41. // cout << "-1\n";
  42. continue;
  43. }
  44.  
  45. else {
  46. if (l != 0) {
  47. x = (cx[r] - cx[l-1]);
  48. y = (cy[r] - cy[l-1]);
  49. }
  50.  
  51. else {
  52. x = cx[r];
  53. y = cy[r];
  54. }
  55.  
  56. cout << x << setprecision(8) << " " << y << setprecision(8) << endl;
  57. }
  58. };
  59. }
  60.  
  61. return 0;
  62. }
Runtime error #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
Standard output is empty