diff --git a/LibreOJ/135/135.cpp b/LibreOJ/135/135.cpp new file mode 100644 index 00000000..83b5f9f9 --- /dev/null +++ b/LibreOJ/135/135.cpp @@ -0,0 +1,76 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = (1 << 12) + 5; + +int n, m, op; +long long c1[N][N], c2[N][N], c3[N][N], c4[N][N]; + +int lowbit(int x) { + return x & -x; +} + +void add(int x, int y, int v) { + for (int i = x; i <= n; i += lowbit(i)) { + for (int j = y; j <= m; j += lowbit(j)) { + c1[i][j] += v; + c2[i][j] += v * x; + c3[i][j] += v * y; + c4[i][j] += v * x * y; + } + } +} + +void add(int x1, int y1, int x2, int y2, int v) { + add(x1, y1, v); + add(x1, y2 + 1, -v); + add(x2 + 1, y1, -v); + add(x2 + 1, y2 + 1, v); +} + +long long sum(int x, int y) { + long long res = 0; + + for (int i = x; i; i -= lowbit(i)) { + for (int j = y; j; j -= lowbit(j)) { + res += (x + 1) * (y + 1) * c1[i][j] + - (y + 1) * c2[i][j] + - (x + 1) * c3[i][j] + + c4[i][j]; + } + } + + return res; +} + +long long sum(int x1, int y1, int x2, int y2) { + return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + while (cin >> op) { + if (op == 1) { + int a, b, c, d, k; + + cin >> a >> b >> c >> d >> k; + + add(a, b, c, d, k); + } else { // op == 2 + int a, b, c, d; + + cin >> a >> b >> c >> d; + + cout << sum(a, b, c, d) << endl; + } + } + + return 0; +} diff --git a/LibreOJ/135/data/1.in b/LibreOJ/135/data/1.in new file mode 100644 index 00000000..fa42e3ad --- /dev/null +++ b/LibreOJ/135/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00827224a0d1da3d8c7b94c4bbed99a5bc6d92d8de0141bb68f085968551c9c8 +size 2932 diff --git a/LibreOJ/135/data/1.out b/LibreOJ/135/data/1.out new file mode 100644 index 00000000..2400fe79 --- /dev/null +++ b/LibreOJ/135/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68de0297a2ebf2c2910a4680f4d9262743e4765e90e02de81743d6b8f9d0e657 +size 640 diff --git a/LibreOJ/135/data/10.in b/LibreOJ/135/data/10.in new file mode 100644 index 00000000..c8fed7d2 --- /dev/null +++ b/LibreOJ/135/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bf8b7edc238f0f80a2f9c20a82f63098d40033435eb1cd378bcf7643421206d +size 4554588 diff --git a/LibreOJ/135/data/10.out b/LibreOJ/135/data/10.out new file mode 100644 index 00000000..e57d2f0b --- /dev/null +++ b/LibreOJ/135/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40ec7bd7af6c8dccf2740b0267679e3601883f7b4c1006f1d978a1df8ae022c9 +size 1157076 diff --git a/LibreOJ/135/data/2.in b/LibreOJ/135/data/2.in new file mode 100644 index 00000000..d6460e8f --- /dev/null +++ b/LibreOJ/135/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2839c8a93dabad39e1656b2a9ccafd21ca37dcad2776aee33d911a00a3a4b167 +size 3935086 diff --git a/LibreOJ/135/data/2.out b/LibreOJ/135/data/2.out new file mode 100644 index 00000000..3a0d292b --- /dev/null +++ b/LibreOJ/135/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c789f48968ab38dccf4eed77e2cd2882df6172b3a8878f238c44887de60b618f +size 1073263 diff --git a/LibreOJ/135/data/3.in b/LibreOJ/135/data/3.in new file mode 100644 index 00000000..989c3323 --- /dev/null +++ b/LibreOJ/135/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abd3a9f98adf3abec9d5d6695a1c5e7621a66fce61adc0d1173aefd8e7824a2a +size 3935818 diff --git a/LibreOJ/135/data/3.out b/LibreOJ/135/data/3.out new file mode 100644 index 00000000..c88a1e5f --- /dev/null +++ b/LibreOJ/135/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77e0c072be298972cea7a9e99b32e659817375961f52dd6277c325924228fb52 +size 1091917 diff --git a/LibreOJ/135/data/4.in b/LibreOJ/135/data/4.in new file mode 100644 index 00000000..4bef06c8 --- /dev/null +++ b/LibreOJ/135/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2a59c864d5fc8b36d539f86fcde1bdb71b537e448b12d4357c9fcfce7ec6f6d +size 3935973 diff --git a/LibreOJ/135/data/4.out b/LibreOJ/135/data/4.out new file mode 100644 index 00000000..52f60b37 --- /dev/null +++ b/LibreOJ/135/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4fae309a08aae48c8d6d1261994cb06ed7b2c08657ccac14453eb4d3d6f5fa17 +size 1059991 diff --git a/LibreOJ/135/data/5.in b/LibreOJ/135/data/5.in new file mode 100644 index 00000000..080dadfc --- /dev/null +++ b/LibreOJ/135/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6431ba59eba9a68f6ea4e338d370bc443876e86d0869bb052ee91fc45ea308c9 +size 3936796 diff --git a/LibreOJ/135/data/5.out b/LibreOJ/135/data/5.out new file mode 100644 index 00000000..89216016 --- /dev/null +++ b/LibreOJ/135/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ed5a5c42dbba8cf66eae0aa010b4062cb39a8b6068e8dacb8c490c97a82825f +size 1101002 diff --git a/LibreOJ/135/data/6.in b/LibreOJ/135/data/6.in new file mode 100644 index 00000000..3d556980 --- /dev/null +++ b/LibreOJ/135/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ace08d9f4699038e9777f0e7cb930bee34d094225c4e30dec6b07a48efc68d9 +size 3935694 diff --git a/LibreOJ/135/data/6.out b/LibreOJ/135/data/6.out new file mode 100644 index 00000000..b5dbd6cf --- /dev/null +++ b/LibreOJ/135/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f7889c4c8d8eb3c66a42a8fc69450d78f86dbede46e207331003bdc585be055 +size 1085783 diff --git a/LibreOJ/135/data/7.in b/LibreOJ/135/data/7.in new file mode 100644 index 00000000..f6987ac2 --- /dev/null +++ b/LibreOJ/135/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:589efc850d310c9ae01e227dde66b8d7a1bec2dc89bef2c68c0b6f9932b49d32 +size 4553759 diff --git a/LibreOJ/135/data/7.out b/LibreOJ/135/data/7.out new file mode 100644 index 00000000..f4f2d120 --- /dev/null +++ b/LibreOJ/135/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7be910b00a8d80b0b36bbe12423583d510b620152df63a0f307a598ec3aff2ce +size 1156794 diff --git a/LibreOJ/135/data/8.in b/LibreOJ/135/data/8.in new file mode 100644 index 00000000..30d59bd9 --- /dev/null +++ b/LibreOJ/135/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95ba646cc79574fc03b4877106a60cf721e4b1ddead0fb517165684a12c1a3b3 +size 4554102 diff --git a/LibreOJ/135/data/8.out b/LibreOJ/135/data/8.out new file mode 100644 index 00000000..cb056697 --- /dev/null +++ b/LibreOJ/135/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6f103ce895ee0bd1a3d966a69f5adc9609bdfcdc43c26c5683bca619806d3e1 +size 1165965 diff --git a/LibreOJ/135/data/9.in b/LibreOJ/135/data/9.in new file mode 100644 index 00000000..2fe23b76 --- /dev/null +++ b/LibreOJ/135/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:919decc8c9ccc4bf7d5e937b81e64a9c90ef42743b0a7c600f2d29cf6bc929c9 +size 4552465 diff --git a/LibreOJ/135/data/9.out b/LibreOJ/135/data/9.out new file mode 100644 index 00000000..ccb14bd6 --- /dev/null +++ b/LibreOJ/135/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30f44be805a5f5fa97ab91635dcb55ef66f38f074fcd6f1d9f546a5ba37e45e7 +size 1162337