#include<stdio.h> #include<algorithm> using namespace std; const int MAX_N = 1e5, MAX_H = 1e3; double bit[3][MAX_H + 2]; int n, m, h[MAX_N]; void update(int t, int x, double y) { for (; x <= MAX_H + 1; x += x&-x) bit[t][x] += y; } double query(int t, int x) { double s = 0; for (; x; x -= x&-x) s += bit[t][x]; return s; } void add(int x, int y, int sw) { if (x == y) { update(0, x + 1, sw*-x); update(1, x + 1, sw); return; } if (x > y) swap(x, y); update(0, x + 1, (double)sw*x*x / 2 / (y - x)); update(1, x + 1, (double)sw*x / (x - y)); update(2, x + 1, (double)sw / 2 / (y - x)); update(0, y + 1, (double)sw*y*y / 2 / (x - y)); update(1, y + 1, (double)sw*y / (y - x)); update(2, y + 1, (double)sw / 2 / (x - y)); } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", h + i); for (int i = 1; i < n; i++) add(h[i - 1], h[i], 1); for (int i = 0; i < m; i++) { char c; int a, b; scanf(" %c", &c); if (c == 'Q') { scanf("%d", &a); printf("%.3lf\n", query(0, a) + query(1, a)*a + query(2, a)*a*a); } else { scanf("%d %d", &a, &b); if (a) add(h[a - 1], h[a], -1); if (a != n - 1) add(h[a], h[a + 1], -1); h[a] = b; if (a) add(h[a - 1], h[a], 1); if (a != n - 1) add(h[a], h[a + 1], 1); } } return 0; }
3990번: 화면 보호기 - 코드 수정 필요
https://www.acmicpc.net/problem/3990
피드 구독하기:
댓글
(
Atom
)
댓글 없음 :
댓글 쓰기