QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283166#6327. Count Arithmetic ProgressionMisukiWA 169ms70220kbC++203.1kb2023-12-13 23:22:342023-12-13 23:22:34

Judging History

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

  • [2023-12-13 23:22:34]
  • 评测
  • 测评结果:WA
  • 用时:169ms
  • 内存:70220kb
  • [2023-12-13 23:22:34]
  • 提交

answer

#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>

#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

namespace R = std::ranges;
namespace V = std::views;

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb

template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
  return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(const T &X : arr)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(const T &X : vec)
    os << X << ' ';
  return os;
}

const int C = 4000000;

signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  int n; cin >> n;
  vector<int> l(n), r(n);
  for(int &x : l)
    cin >> x;
  for(int &x : r)
    cin >> x;

  auto evalL = [&](int a, int x) { return l[x] - a * x; };
  auto evalR = [&](int a, int x) { return r[x] - a * x; };

  vector<int> ans(2 * C + 1);
  auto dc = [&](int l, int r, int ql, int qr, auto self) -> void {
    if (ql == qr) return;
    int a = (ql + qr + 2 * C) / 2 - C, best = l;
    for(int i = l + 1; i < r; i++)
      if (evalL(a, i) > evalL(a, best))
        best = i;
    ans[a + C] = -evalL(a, best);
    self(l, best + 1, a + 1, qr, self);
    self(best, r, ql, a, self);
  };

  auto dc2 = [&](int l, int r, int ql, int qr, auto self) -> void {
    if (ql == qr) return;
    int a = (ql + qr + 2 * C) / 2 - C, best = l;
    for(int i = l + 1; i < r; i++)
      if (evalR(a, i) < evalR(a, best))
        best = i;
    ans[a + C] += evalR(a, best) + 1;
    self(l, best + 1, ql, a, self);
    self(best, r, a + 1, qr, self);
  };

  dc(0, n, -C, C, dc);
  dc2(0, n, -C, C, dc2);

  int tot = 0;
  for(int i = 0; i < ssize(ans); i++)
    tot = (tot + max(ans[i], 0ll)) % 998244353;

  cout << tot << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 100ms
memory: 65712kb

input:

3
5 5 2
7 6 7

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 104ms
memory: 65700kb

input:

4
2 3 1 6
5 6 4 8

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 169ms
memory: 70220kb

input:

300000
121398540794 60081434790 252920491076 43666218735 95583832019 21178121624 315727133812 89837170656 138389231466 174687947367 124350262341 108583578309 289629745492 321006985392 301201031648 138149017169 255983300245 138801256482 285614769875 130583757928 261690466826 74624776159 303504239011 ...

output:

2000014

result:

ok 1 number(s): "2000014"

Test #4:

score: -100
Wrong Answer
time: 98ms
memory: 65648kb

input:

2
1 1
1000000000000 1000000000000

output:

597835303

result:

wrong answer 1st numbers differ - expected: '276262510', found: '597835303'