QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#554146 | #9255. Python Program | MiniLong | AC ✓ | 10ms | 3692kb | C++17 | 4.3kb | 2024-09-09 07:51:22 | 2024-09-09 07:51:22 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
char ibuf[50007],*p1 = ibuf, *p2 = ibuf;
#ifdef ONLINE_JUDGE
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
string s, ch;
ll solve(int i){
int d = 0, e = 0, f = 1, x = 0;
int pos = 19;
if(s[pos] == ch[4]) d = i, pos += 2;
else{
int cur = 0;
_rep(j, pos, s.size() - 1){
if(s[j] == ',') break;
x = x * 10 + s[j] - '0', cur = j;
}
d = x, pos = cur + 2;
}
if(s[pos] == ch[4]) e = i, pos += 2;
else{
int cur = 0; x = 0;
_rep(j, pos, s.size() - 1){
if(s[j] == ',' || s[j] == ')') break;
x = x * 10 + s[j] - '0', cur = j;
}
e = x, pos = cur + 2;
}
if(s[pos] == ':') f = 1;
else{
if(s[pos] == ch[4]) f = i;
else{
int cur = 0, op = 1; x = 0;
_rep(j, pos, s.size() - 1){
if(s[j] == ')') break;
if(s[j] == '-') op = -op;
else x = x * 10 + s[j] - '0', cur = j;
}
f = x * op;
}
}
// debug("i:%d d:%d e:%d f:%d\n", i, d, e, f);
ll sum = 0;
if(f > 0){
if(e > d){
ll k = (e - d - 1) / f;
sum = d * (k + 1) + (1 + k) * k / 2 * f;
}
}else{
if(e < d){
ll k = (d - (e + 1)) / (-f);
sum = d * (k + 1) + (1 + k) * k / 2 * f;
}
}
return sum;
}
int main(){
getline(cin, s);
getline(cin, s);
int x = 0, a = 0, b = 0, c = 1, cnt = 0;
int op = 1;
int pos = 15;
_rep(i, pos, s.size() - 1){
if(s[i] == '-'){op = -1; continue;}
if(!(s[i] >= '0' && s[i] <= '9')){
if(!cnt) a = x * op;
if(cnt == 1) b = x * op;
if(cnt == 2 && x) c = x * op;
cnt++, x = 0, op = 1;
}else x = x * 10 + s[i] - '0';
}
ch = s;
getline(cin, s);
ll ans = 0;
if(c > 0){
for(int i = a; i < b; i += c){
ans += solve(i);
}
}else{
for(int i = a; i > b; i += c){
ans += solve(i);
}
}
writeln(ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3692kb
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: 7ms
memory: 3636kb
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: 2ms
memory: 3656kb
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: 10ms
memory: 3636kb
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