QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398367#3768. 矩形并SamponYW#AC ✓4ms3844kbC++141.7kb2024-04-25 11:12:342024-04-25 11:12:37

Judging History

This is the latest submission verdict.

  • [2024-04-25 11:12:37]
  • Judged
  • Verdict: AC
  • Time: 4ms
  • Memory: 3844kb
  • [2024-04-25 11:12:34]
  • Submitted

answer

#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 1000005
#define P 1000000007
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
int a, b, xl, xr, yl, yr;
il int slv(int a, int n) {
  if(a <= n) return 1ll * a * (a + 1) / 2 % P;
  return add(1ll * n * (n + 1) / 2 % P, 1ll * (a - n) * n % P);
}
il int calc(int n, int m) {
  /*
  \sum min(i, n) * min(j, m)
  */
  return 1ll * slv(a, n) * slv(b, m) % P;
}
il void WORK() {
  cin >> xl >> xr >> yl >> yr;
  int ans = add(calc(xr, yr), calc(xl, yl));
  addr(ans, P - add(calc(xr, yl), calc(xl, yr)));
  int A = 1ll * (1ll * a * (a + 1) / 2 % P) * (1ll * b * (b + 1) / 2 % P) % P;
  addr(A, 1ll * a * b % P * (xr - xl) % P * (yr - yl) % P);
  cout << add(A, P - ans) << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  while(cin >> a >> b) WORK();
  cerr << 1.0 * clock() / CLOCKS_PER_SEC;
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3844kb

input:

1 1
2 3 2 3
10 10
1 5 1 5
1000000000 1000000000
1 1000000000 1 1000000000
1 2
2 5 1 4
2 5
1 5 2 4
1 4
3 4 1 5
2 3
1 4 2 4
5 3
1 4 1 2
5 2
3 5 4 5
3 2
3 5 1 4
5 3
4 5 1 3
5 5
1 5 2 5
4 4
1 5 2 5
1 2
1 5 3 5
3 4
3 4 1 2
2 2
1 4 1 3
3 1
1 4 1 4
2 4
1 5 2 5
4 2
2 3 3 5
1 3
1 2 1 2
2 4
1 3 1 5
5 2
2 3 2 ...

output:

2
3725
2793
21
120
26
53
117
65
54
117
465
274
19
72
32
33
123
46
9
88
65
36
252
83
159
17
330
261
186
84
26
45
34
75
34
65
30
88
107
12
105
38
46
15
85
29
55
78
55
96
17
39
60
20
17
56
45
5
18
96
30
25
108
146
114
65
19
192
51
17
42
54
132
110
75
42
75
66
150
7
7
173
33
95
75
294
45
247
25
35
110
2...

result:

ok 10000 lines