QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549992#9255. Python Programucup-team896#AC ✓8ms3680kbC++202.3kb2024-09-07 08:28:002024-09-07 08:53:28

Judging History

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

  • [2024-09-07 08:53:28]
  • 管理员手动重测本题所有提交记录
  • 测评结果:AC
  • 用时:8ms
  • 内存:3680kb
  • [2024-09-07 08:28:01]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3684kb
  • [2024-09-07 08:28:00]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

char lst;

pii get() {
  int res = 0, op = 0;
  char ch = getchar();
  if (ch != '-' && !isdigit(ch)) return lst = getchar(), pii(0, int(ch));
  if (ch == '-') op = 1, ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
  lst = ch;
  return pii(1, op ? -res : res);
}

int main() {
  char ch = getchar();
  while (ch != 'r') ch = getchar();
  ch = getchar();
  int A = int(getchar());
  while (ch != '(') ch = getchar();
  int Al = get().se;
  int Ar = get().se;
  int Ad = 1;
  if (lst == ',') Ad = get().se;
  ch = getchar();
  while (ch != '(') ch = getchar();
  pii Bl = get(), Br = get(), Bd = pii(1, 1);
  if (lst == ',') Bd = get();
  auto getsum = [&](int L, int R, int D) {
    ll res = 0;
    if (D > 0) {
      // for (int i = L; i < R; i += D) res += i;
      if (R <= L) return 0ll;
      int lim = R / D * D + (L % D + D) % D;
      while (lim < R) lim += D;
      while (lim >= R) lim -= D;
      int l = L, r = lim, x = (r - l) / D + 1;
      return 1ll * x * (l + r) / 2;
    } else {
      if (R >= L) return 0ll;
      // cerr << L << " " << R << " " << D << endl;
      D = -D;
      int lim = R / D * D + (L % D + D) % D;
      while (lim > R) lim -= D;
      while (lim <= R) lim += D;
      int l = lim, r = L, x = (r - l) / D + 1;
      // cerr << l << " " << r << endl;
      return 1ll * x * (l + r) / 2;
    }
    // cerr << res << endl;
    return res;
  };
  auto calc = [&](int p) {
    int L = (Bl.fi ? Bl.se : p);
    int R = (Br.fi ? Br.se : p);
    int D = (Bd.fi ? Bd.se : p);
    return getsum(L, R, D);
  };
  ll ans = 0;
  if (Ad > 0) {
    for (int i = Al; i < Ar; i += Ad) {
      ans += calc(i);
    }
  } else {
    Ad = -Ad;
    for (int i = Al; i > Ar; i -= Ad) {
      ans += calc(i);
    }
  }
  cout << ans << '\n';
}

详细

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: 3620kb

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: 8ms
memory: 3592kb

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: 3664kb

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: 7ms
memory: 3680kb

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