QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779771 | #9255. Python Program | wanggl# | AC ✓ | 68ms | 3616kb | C++17 | 6.8kb | 2024-11-24 21:42:30 | 2024-11-24 21:42:32 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define x first
#define y second
#define db cout<< "debug" <<endl;
#define rep1(a) for (auto i = 0; i < a; i++)
#define rep2(i, a) for (auto i = 0; i < a; i++)
#define rep3(i, a, b) for (auto i = a; i < b; i++)
#define rep4(i, a, b, c) for (auto i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x), end(x)
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PIII = pair<pair<int, int>, int>;
const int N = 1e6 + 10, inf = 1e18;
void solve() {
string s;
cin >> s;
cin >> s;
cin >> s;
string I = s;
cin >> s;
cin >> s;
int a = 0, b = 0, c = 0;
int cnt = 0;
for (auto it : s) {
if (it == ',') {
cnt++;
}
}
if (cnt == 1) {
c = 1;
int pos = 6;
if (s[6] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
a = a * 10 + s[i] - '0';
pos = i;
}
if (s[6] == '-') a = -a;
pos += 2;
int pos2 = pos;
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ')'; i++) {
b = b * 10 + s[i] - '0';
}
if (s[pos2] == '-') b = -b;
} else {
int pos = 6;
if (s[6] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
a = a * 10 + s[i] - '0';
pos = i;
}
if (s[6] == '-') a = -a;
pos += 2;
int pos2 = pos;
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
b = b * 10 + s[i] - '0';
pos = i;
}
if (s[pos2] == '-') b = -b;
pos += 2;
pos2 = pos;
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ')'; i++) {
c = c * 10 + s[i] - '0';
}
if (s[pos2] == '-') c = -c;
}
// cout << a << " " << b << " " << c << endl;
int d = 0, e = 0, f = 0;
bool f1 = 0, f2 = 0, f3 = 0;
cin >> s;
cin >> s;
string J = s;
cin >> s;
cin >> s;
cnt = 0;
for (auto it : s) {
if (it == ',') {
cnt++;
}
}
if (cnt == 1) {
f = 1;
int pos = 6;
if (s[pos] != '-' && (s[pos] < '0' || s[pos] > '9')) {
f1 = 1;
while (s[pos + 1] != ',') pos++;
} else {
if (s[6] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
d = d * 10 + s[i] - '0';
pos = i;
}
if (s[6] == '-') d = -d;
}
pos += 2;
int pos2 = pos;
if (s[pos2] != '-' && (s[pos2] < '0' || s[pos2] > '9')) {
f2 = 1;
} else {
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ')'; i++) {
e = e * 10 + s[i] - '0';
}
if (s[pos2] == '-') e = -e;
}
} else {
int pos = 6;
if (s[pos] != '-' && (s[pos] < '0' || s[pos] > '9')) {
f1 = 1;
while (s[pos + 1] != ',') pos++;
} else {
if (s[6] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
d = d * 10 + s[i] - '0';
pos = i;
}
if (s[6] == '-') d = -d;
}
pos += 2;
int pos2 = pos;
if (s[pos2] != '-' && (s[pos2] < '0' || s[pos2] > '9')) {
f2 = 1;
while (s[pos + 1] != ',') pos++;
} else {
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ','; i++) {
e = e * 10 + s[i] - '0';
pos = i;
}
if (s[pos2] == '-') e = -e;
}
pos += 2;
pos2 = pos;
if (s[pos2] != '-' && (s[pos2] < '0' || s[pos2] > '9')) {
f3 = 1;
} else {
if (s[pos2] == '-') pos++;
for (int i = pos; s[i] != ')'; i++) {
f = f * 10 + s[i] - '0';
}
if (s[pos2] == '-') f = -f;
}
}
// cout << d << " " << e << " " << f << endl;
int ans = 0;
if (c > 0) {
for (int i = a; i < b; i += c) {
if (f1) d = i;
if (f2) e = i;
if (f3) f = i;
if (f > 0) {
int l = 0, r = 1e9, n = l;
while (l <= r) {
int mid = (l + r) / 2;
if (d + mid * f < e) {
l = mid + 1;
n = mid;
} else {
r = mid - 1;
}
}
n++;
if (d < e) ans += n * d + n * (n - 1) / 2 * f;
} else {
int l = 0, r = 1e9, n = l;
while (l <= r) {
int mid = (l + r) / 2;
if (d + mid * f > e) {
l = mid + 1;
n = mid;
} else {
r = mid - 1;
}
}
// cout << n << endl;
n++;
if (d > e) ans += n * d + n * (n - 1) / 2 * f;
}
}
} else {
for (int i = a; i > b; i += c) {
if (f1) d = i;
if (f2) e = i;
if (f3) f = i;
if (f > 0) {
int l = 0, r = 1e9, n = l;
while (l <= r) {
int mid = (l + r) / 2;
if (d + mid * f < e) {
l = mid + 1;
n = mid;
} else {
r = mid - 1;
}
}
n++;
if (d < e) ans += n * d + n * (n - 1) / 2 * f;
} else {
int l = 0, r = 1e9, n = l;
while (l <= r) {
int mid = (l + r) / 2;
if (d + mid * f > e) {
l = mid + 1;
n = mid;
} else {
r = mid - 1;
}
}
n++;
if (d > e) ans += n * d + n * (n - 1) / 2 * f;
}
}
}
cin >> s;
cin >> s;
cout << ans << "\n";
}
signed main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int _T = 1;
//cin >> _T;
rep (_T) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
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: 3528kb
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: 67ms
memory: 3616kb
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: 8ms
memory: 3528kb
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: 68ms
memory: 3612kb
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