QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#541034#3768. 矩形并abovecloud#AC ✓17ms3640kbC++141.2kb2024-08-31 18:26:542024-08-31 18:26:54

Judging History

This is the latest submission verdict.

  • [2024-08-31 18:26:54]
  • Judged
  • Verdict: AC
  • Time: 17ms
  • Memory: 3640kb
  • [2024-08-31 18:26:54]
  • Submitted

answer

	/*Time:2024-08-31 16:42:53*/
	#include <bits/stdc++.h>

	#define pii pair<int,int>
	#define vi vector<int>
	#define vvi vector<vi>
	#define int long long
	using namespace std;
	const int MOD = (int) 1e9 + 7;
	const int MAXN = 200005;
	int a,b,x,y,xx,yy;
	int ksm(int a,int n){
	    int ans=1;
	    for(int i=0;i<=30;i++){
	        if(n&(1ll<<i))ans=ans*a%MOD;
	        a=a*a%MOD;
	    }
	    return ans;
	}
	void solve() {
		// if(xx<=a || yy<=b){
		// 	cout<<0<<endl;
		// 	return;
		// }
		
		int inv2=ksm(2,MOD-2);
		int ans = (1+a) * a % MOD * inv2 % MOD * (1+b) % MOD * b %MOD * inv2 %MOD;
		ans += (xx-x)*(yy-y)%MOD*a%MOD*b%MOD;
		ans%=MOD;
		if(a>x&&b>y){
			int l1=max(1ll,a-xx+1),r1=a-x;
			int l2=max(1ll,b-yy+1),r2=b-y;
			int k=(l2+r2)%MOD * (r2-l2+1) % MOD * inv2 % MOD * (l1+r1)%MOD * (r1-l1+1) % MOD * inv2 % MOD;
			ans=ans-k+MOD;
			// cout<<k<<endl;
			// cout<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<" "<<endl;
			ans%=MOD;
		}
		
		
		// ans=ans*k%MOD;

		cout<<ans<<endl;
	}

	int32_t main() {
	    std::ios::sync_with_stdio(false);
	    std::cin.tie(nullptr);
	    int T = 1;

	    // cin >> T;
	    while (cin >> a >>b>>x>>xx>>y>>yy)solve();
	}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 17ms
memory: 3640kb

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