版本比较
QOJ3676 Joined Vessels
正文
增加 7 行删除 7 行
35 行未改动363738394041424344457 行未改动5354555657585960617 行未改动697071727374757677787980818283848523 行未改动10911011111211311411535 行未改动i64 Ls[18][N], Rs[18][N];void prework() {copy(a + 1, a + n, st[0] + 1);for (int i = 1; (1 << i) < n; i++)for (int j = 1; j + (1 << i) - 1 < n; j++)st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);stack<int> st;for (int i = 1; i < n; i++) {while (!st.empty() && a[st.top()] < a[i]) st.pop();7 行未改动st.emplace(i);}for (int i = 1; i < n; i++) Ls[0][i] = 1LL * a[i] * (i - L[0][i]), Rs[0][i] = 1LL * a[i] * (R[0][i] - i);R[0][n] = n;for (int i = 1; i <= lg(n); i++)for (int j = 0; j <= n; j++) {L[i][j] = L[i - 1][L[i - 1][j]], R[i][j] = R[i - 1][R[i - 1][j]];Ls[i][j] = Ls[i - 1][j] + Ls[i - 1][L[i - 1][j]];Rs[i][j] = Rs[i - 1][j] + Rs[i - 1][R[i - 1][j]];7 行未改动i64 res = 0;for (int i = lg(n); i >= 0; i--) {if (R[i][l] > r) continue;res += Rs[i][l], l = R[i][l];}return res + 1LL * a[l] * (r - l + 1);}i64 qsuf(int l, int r) {i64 res = 0;for (int i = lg(n); i >= 0; i--) {if (L[i][r] < l) continue;res += Ls[i][r], r = L[i][r];}return res + 1LL * a[r] * (r - l + 1);}i64 ask1(int l, int r) {23 行未改动cin >> u >> v;if (u < v) cout << ask1(u, v) << '\n';else cout << ask2(u, v) << '\n';}}```:::::35 行未改动363738394041424344457 行未改动5354555657585960617 行未改动697071727374757677787980818283848523 行未改动10911011111211311411535 行未改动i64 Ls[18][N], Rs[18][N];void prework() {copy(a + 1, a + n, st[0] + 1);for (int i = 1; (1 << i) < n; i++)for (int j = 1; j + (1 << i) - 1 < n; j++)st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);stack<int> st;for (int i = 1; i < n; i++) {while (!st.empty() && a[st.top()] < a[i]) st.pop();7 行未改动st.emplace(i);}for (int i = 1; i < n; i++) Ls[0][i] = 1LL * a[i] * (i - L[0][i]), Rs[0][i] = 1LL * a[i] * (R[0][i] - i);R[0][n] = n;for (int i = 1; i <= lg(n); i++)for (int j = 0; j <= n; j++) {L[i][j] = L[i - 1][L[i - 1][j]], R[i][j] = R[i - 1][R[i - 1][j]];Ls[i][j] = Ls[i - 1][j] + Ls[i - 1][L[i - 1][j]];Rs[i][j] = Rs[i - 1][j] + Rs[i - 1][R[i - 1][j]];7 行未改动i64 res = 0;for (int i = lg(n); i >= 0; i--) {if (R[i][l] > r) continue;res += Rs[i][l], l = R[i][l];}return res + 1LL * a[l] * (r - l + 1);}i64 qsuf(int l, int r) {i64 res = 0;for (int i = lg(n); i >= 0; i--) {if (L[i][r] < l) continue;res += Ls[i][r], r = L[i][r];}return res + 1LL * a[r] * (r - l + 1);}i64 ask1(int l, int r) {23 行未改动cin >> u >> v;if (u < v) cout << ask1(u, v) << '\n';else cout << ask2(u, v) << '\n';}}```:::::