QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#556246 | #9255. Python Program | no_RED_no_DEAD | AC ✓ | 97ms | 3840kb | C++20 | 3.8kb | 2024-09-10 16:12:47 | 2024-09-10 16:12:47 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll N = 1e6 + 1;
const ll M = 1e9 + 7;
void doTest(ll testID) {
string s; getline(cin, s);
// 2
getline(cin, s);
string fc = {s[4]};
ll ist = 0, ied = 0, iic = 0, j = 0, k = -1;
ll sign_ist = 1, sign_ied = 1, sign_iic = 1;
for (int i = 15;; i ++) {
if (s[i] == ',') {j = i + 1; break;}
if (s[i] == '-') {sign_ist = -1; continue;}
ist = ist * 10 + (s[i] - '0');
}
for (; j < s.size(); j ++) {
if (s[j] == ')') {break;}
if (s[j] == ',') {k = j + 1; break;}
if (s[j] == '-') {sign_ied = -1; continue;}
ied = ied * 10 + (s[j] - '0');
}
if (k != -1) {
for (; k < s.size(); k ++) {
if (s[k] == ')') {break;}
if (s[k] == '-') {sign_iic = -1; continue;}
iic = iic * 10 + (s[k] - '0');
}
} else iic = 1;
ist *= sign_ist, ied *= sign_ied, iic *= sign_iic;
// 3
getline(cin, s);
string s_jst, s_jed, s_jic; j = 0, k = -1;
ll sign_jst = 1, sign_jed = 1, sign_jic = 1;
for (int i = 19;; i ++) {
if (s[i] == ',') {j = i + 1; break;}
if (s[i] == '-') {sign_jst = -1; continue;}
s_jst += s[i];
}
for (; j < s.size(); j ++) {
if (s[j] == ')') {break;}
if (s[j] == ',') {k = j + 1; break;}
if (s[j] == '-') {sign_jed = -1; continue;}
s_jed += s[j];
}
if (k != -1) {
for (; k < s.size(); k ++) {
if (s[k] == ')') {break;}
if (s[k] == '-') {sign_jic = -1; continue;}
s_jic += s[k];
}
} else s_jic = "1";
// cout << "Line 2: " << ist << ' ' << ied << ' ' << iic << endl;
// cout << "Line 3: " << s_jst << ' ' << s_jed << ' ' << s_jic << endl;
ll fres = 0;
ll i = ist;
while (true) {
if (iic > 0 && i >= ied) break;
if (iic < 0 && i <= ied) break;
ll fi, se, rd;
if (s_jst == fc) fi = i; else fi = stoll(s_jst);
if (s_jed == fc) se = i; else se = stoll(s_jed);
if (s_jic == fc) rd = i;
else if (s_jic == '-' + fc) rd = -i;
else rd = stoll(s_jic) * sign_jic;
// cout << "Data: " << fi << ' ' << se << ' ' << rd << endl;
if (rd >= 1) {
if (se > fi) {
ll small = fi, large = se;
// CT: small + k * rd < large
ll l = 0, r = 1e9, mid, res = -1;
while (r >= l) {
mid = (r + l) >> 1;
if (small + mid * rd < large) l = (res = mid) + 1;
else r = mid - 1;
}
large = small + res * rd;
fres += (large + small) * ((large - small) / rd + 1) / 2;
}
} else {
if (fi > se) {
ll small = se, large = fi; rd = abs(rd);
// CT: large - k * rd > small
ll l = 0, r = 1e9, mid, res = -1;
while (r >= l) {
mid = (r + l) >> 1;
if (large - mid * rd > small) l = (res = mid) + 1;
else r = mid - 1;
}
small = large - res * rd;
// cout << "Debug: " << small << ' ' << large << ' ' << (large + small) << ' ' << ((large - small + 1) / rd) << endl;
fres += (large + small) * ((large - small) / rd + 1) / 2;
}
}
// cout << "??????: " << i << ' ' << iic << endl;
i += iic;
}
cout << fres;
getline(cin, s); getline(cin, s);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int test = 1;
// cin >> test;
for (int _ = 1; _ <= test; _ ++) doTest(test);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
ans=0 for q in range(100,50,-1): for i in range(q,77,20): ans+=i print(ans)
output:
2092
result:
ok single line: '2092'
Test #3:
score: 0
Accepted
time: 97ms
memory: 3596kb
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)
output:
166666666665500001
result:
ok single line: '166666666665500001'
Test #4:
score: 0
Accepted
time: 13ms
memory: 3616kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
11756963404587200
result:
ok single line: '11756963404587200'
Test #5:
score: 0
Accepted
time: 89ms
memory: 3832kb
input:
ans=0 for i in range(1,1000000): for j in range(i,114514,-1): ans+=j print(ans)
output:
160610445975856765
result:
ok single line: '160610445975856765'
Extra Test:
score: 0
Extra Test Passed