Advertisement
GerONSo

9 ЛКШ tle9

Apr 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #define pragma
  2.  
  3. #ifdef pragma
  4. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
  5. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. #endif // pragma
  7.  
  8. #include<bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. #define ll long long
  13. #define all(x) begin(x), end(x)
  14. #define pb push_back
  15. #define x first
  16. #define y second
  17. #define int long long
  18. #define zero(two) memset(two, 0, sizeof(two))
  19.  
  20. using namespace std;
  21. using namespace __gnu_pbds;
  22.  
  23.  
  24. typedef vector<int> vi;
  25. typedef vector<bool> vb;
  26. typedef pair<int, int> pii;
  27. typedef long double ld;
  28. typedef vector<vi> matrix;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(10);
  39. #if _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 2e3 + 10;
  46. const int INF = 1e18 + 7;
  47. const int MAXLOG = 20;
  48. const int MOD = 998244353;
  49. const int BASE = 47;
  50.  
  51. signed main() {
  52. seriy();
  53. int n, q;
  54. cin >> n >> q;
  55. vector<ld> a(n);
  56. ld sum = 0;
  57. ld mx = 0;
  58. for(int i = 0; i < n; i++) {
  59. cin >> a[i];
  60. sum += a[i];
  61. mx = max(mx, a[i]);
  62. }
  63. sum -= a[0] / 2.;
  64. sum -= a[n - 1] / 2.;
  65. while(q--) {
  66. char t;
  67. cin >> t;
  68. if(t == 'Q') {
  69. int p;
  70. cin >> p;
  71. ld cur = 0;
  72. for(int i = 1; i < n; i++) {
  73. bool swp = 0;
  74. if(a[i - 1] > p && a[i] < p) {
  75. swap(a[i], a[i - 1]);
  76. swp = 1;
  77. }
  78. if(a[i - 1] < p && a[i] > p) {
  79. cur += (a[i] - p) * (a[i] - p) / (2. * (a[i] - a[i - 1]));
  80. }
  81. else if(a[i - 1] >= p && a[i] >= p) {
  82. cur += (a[i] + a[i - 1] - 2 * p) / 2.;
  83. }
  84. if(swp) {
  85. swap(a[i], a[i - 1]);
  86. }
  87. }
  88.  
  89. ld ans = mx * (n - 1) - sum + cur;
  90. // cerr << sum << '\n';
  91. ans += (p - mx) * (n - 1);
  92. cout << ans << '\n';
  93. }
  94. else {
  95. int pos;
  96. ld val;
  97. cin >> pos >> val;
  98. if(pos == 0 || pos == n - 1) {
  99. sum -= a[pos] / 2.;
  100. a[pos] = val;
  101. sum += a[pos] / 2.;
  102. }
  103. else {
  104. sum -= a[pos];
  105. a[pos] = val;
  106. sum += a[pos];
  107. }
  108. mx = 0;
  109. for(int i = 0; i < n; i++) {
  110. mx = max(mx, a[i]);
  111. }
  112. }
  113. }
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement