QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701481 | #9255. Python Program | 53Dawns# | AC ✓ | 3ms | 3860kb | C++23 | 4.5kb | 2024-11-02 14:15:39 | 2024-11-02 14:15:39 |
Judging History
answer
//Author: Puremg
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC optimize(3,"Ofast")
#include <bits/stdc++.h>
#define deg(a) cout<<#a<<'='<<a<<"\n"
#define int long long
#define all(a) a.begin(), a.end()
// #define db double
#define ldb long double
#define db ldb
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int mod = 0 + 7;
const int N = 1e6+10;
const db eps = 1e-12;
const db pi = acos(-1);
mt19937_64 rng(random_device{}());
void solve() {
string s;
getline(cin, s);
string a;
getline(cin, a);
a = ' ' + a;
while (1) {
char ok;
cin >> ok;
if (ok != ' ') break;
}
int l = 0, r = 0, z = 0;
char chh = a[5];
string ch = "";
ch += chh;
string ll, rr, zz;
int idx = 16;
while (a[idx] != ',') idx ++;
ll = a.substr(16, idx - 16);
idx ++;
while (a[idx] != ',' and a[idx] != ')') {
rr += a[idx];
idx ++;
}
if (a[idx] == ')') {
zz = "1";
} else {
idx ++;
while (a[idx] != ',' and a[idx] != ')') {
zz += a[idx];
idx ++;
}
}
l = stoll(ll);
r = stoll(rr);
z = stoll(zz);
getline(cin, a);
a = 'f' + a;
a = ' ' + a;
//deg(a);
// return ;
ll = "", rr = "", zz = "";
idx = 16;
while (a[idx] != ',') idx ++;
ll = a.substr(16, idx - 16);
idx ++;
while (a[idx] != ',' and a[idx] != ')') {
rr += a[idx];
idx ++;
}
if (a[idx] == ')') {
zz = "1";
} else {
idx ++;
while (a[idx] != ',' and a[idx] != ')') {
zz += a[idx];
idx ++;
}
}
auto get = [&](int shou, int cha, int r) -> int {
if (shou == r) return 0;
if (cha > 0) if(shou > r) return 0;
if (cha < 0) if (shou < r) return 0;
int n;
if (cha > 0)
n = max(0ll,(r - 1 - shou) / cha) + 1;
else
n = max(0ll,(r + 1 - shou) / cha) + 1;
return n * (shou + shou + (n - 1) * cha) / 2;
};
if (ll == ch and rr == ch and zz == ch) {
cout << 0 << '\n';
} else if(ll == ch and rr == ch) {
cout << 0 << '\n';
}
else if (ll == ch and zz == ch) {
int ans = 0;
int r2 = stoll(rr);
if (z > 0)
for (int i = l; i < r; i += z) {
ans += get(i, i, r2);
}
else
for (int i = l; i > r; i += z) {
ans += get(i, i, r2);
}
cout << ans << '\n';
} else if (rr == ch and zz == ch) {
int ans = 0;
int l2 = stoll(ll);
if (z > 0)
for (int i = l; i < r; i += z) {
ans += get(l2, i, i);
}
else
for (int i = l; i > r; i += z) {
ans += get(l2, i, i);
}
cout << ans << '\n';
} else if (ll == ch) {
int ans = 0;
int r2 = stoll(rr);
int z2 = stoll(zz);
if (z < 0) {
for (int i = l; i > r; i += z) {
ans += get(i, z2, r2);
}
} else {
for (int i = l; i < r; i += z) {
ans += get(i, z2, r2);
}
}
cout << ans << '\n';
} else if (rr == ch) {
int ans = 0;
int l2 = stoll(ll);
int z2 = stoll(zz);
if (z > 0)
for (int i = l; i < r; i += z) {
ans += get(l2, z2, i);
}
else
for (int i = l; i > r; i += z) {
ans += get(l2, z2, i);
}
cout << ans << '\n';
} else if (zz == ch) {
int ans = 0;
int l2 = stoll(ll);
int r2 = stoll(rr);
if (z > 0)
for (int i = l; i < r; i += z) {
ans += get(l2, i, r2);
}
else
for (int i = l; i > r; i += z) {
ans += get(l2, i, r2);
}
cout << ans << '\n';
} else {
int ans = 0;
int l2 = stoll(ll);
int r2 = stoll(rr);
int z2 = stoll(zz);
if (z > 0)
for (int i = l; i < r; i += z) {
ans += get(l2, z2, r2);
}
else
for (int i = l; i > r; i += z) {
ans += get(l2, z2, r2);
}
cout << ans << '\n';
}
}
signed main()
{
// auto start_time = std::chrono::high_resolution_clock::now();
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(15);
int T = 1;
// cin >> T;
while (T--) solve();
// auto end_time = std::chrono::high_resolution_clock::now();
// auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
// std::cout << "程序运行时间:" << duration.count() << "毫秒" << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 3588kb
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: 0ms
memory: 3656kb
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: 1ms
memory: 3860kb
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: 3ms
memory: 3588kb
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