QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139004#3004. It's a Mod, Mod, Mod, Mod Worldkaruna#TL 2083ms3496kbC++17958b2023-08-12 16:09:042023-08-12 16:09:05

Judging History

你现在查看的是最新测评结果

  • [2023-08-12 16:09:05]
  • 评测
  • 测评结果:TL
  • 用时:2083ms
  • 内存:3496kb
  • [2023-08-12 16:09:04]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int B = 1000;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	
	int T; cin >> T;
	while(T--)
	{
		int p, q, n; cin >> p >> q >> n;
		long long ans = 0;
		int t = n / B;
		for(int i = t * B; i <= n; ++i) ans += 1ll * i * p % q;
		if(t)
		{
			int A[B];
			long long s = 0;
			for(int i = 0; i < B; ++i) A[i] = 1ll * i * p % q, s += A[i];
			sort(A, A + B);

			long long l = 0;
			int K[t];
			for(int i = 0; i < t; ++i) K[i] = 1ll * B * i * p % q, l += K[i];
			sort(K, K + t);

			long long m = 0;
			int pt = B;
			for(auto k : K)
			{
				while(pt > 0 && A[pt - 1] >= q - k) --pt;
				m += B - pt;
			}

			ans += s * t + B * l - m * q;
		}
		cout << ans << '\n';
	}
}

详细

Test #1:

score: 100
Accepted
time: 2083ms
memory: 3492kb

input:

91125
999956 999956 999956
999956 999956 999957
999956 999956 999958
999956 999956 999959
999956 999956 999960
999956 999956 999961
999956 999956 999962
999956 999956 999963
999956 999956 999964
999956 999956 999965
999956 999956 999966
999956 999956 999967
999956 999956 999968
999956 999956 999969
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
499956500946
499956500946
499957500902
499958500857
499959500811
499960500764
499961500716
499962500667
499963500617
499964500566
499965500514
499966500461
499967500407
499968500352
499969500296
499970500239
49...

result:

ok 91125 lines

Test #2:

score: 0
Accepted
time: 92ms
memory: 3496kb

input:

8000
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 1 999991
1 1 999992
1 1 999993
1 1 999994
1 1 999995
1 1 999996
1 1 999997
1 1 999998
1 1 999999
1 1 1000000
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 999991
1 2 999992
1 2 999993
1 2 999994
1 2 999995
1 2 999...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
2
2
3
3
4
4
5
5
499996
499996
499997
499997
499998
499998
499999
499999
500000
500000
1
3
3
4
6
6
7
9
9
10
999991
999993
999993
999994
999996
999996
999997
999999
999999
1000000
1
3
6
6
7
9
12
12
13
15
1499988
1499988
1499989
1499991
1499994
1499994
149999...

result:

ok 8000 lines

Test #3:

score: -100
Time Limit Exceeded

input:

100000
848401 999985 1000000
999527 999616 1000000
999789 999914 1000000
999479 999722 1000000
999841 999933 1000000
406226 999991 1000000
940598 999982 1000000
999708 999994 1000000
948123 999993 1000000
999789 999851 1000000
999522 999893 1000000
999977 999983 1000000
999912 999924 1000000
999232 ...

output:

499992309650
499992847584
499999028720
499990037714
499999288213
499994780341
499990845156
499998993982
499997047626
499998796124
499997350691
499999498946
499993962456
499999037615
499998396930
499994213619
499996210819
499998734816
499998193499
499997294296
499997311600
499997563064
499998257020
4...

result: