QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#474644#5500. BarspiratZnachor#WA 196ms4256kbC++144.1kb2024-07-12 21:35:152024-07-12 21:35:15

Judging History

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

  • [2024-07-12 21:35:15]
  • 评测
  • 测评结果:WA
  • 用时:196ms
  • 内存:4256kb
  • [2024-07-12 21:35:15]
  • 提交

answer

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define BOOST ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
void test_case() {
    int n;
    cin >> n;
    vector<int> taken(n, 0);
    vi v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    vi pre(n, -1), suf(n, -1);
    vi prel(n, -1), sufr(n, -1);
    pre[0] = v[0];
    prel[0] = 0;
    for(int i = 1; i < n; i++) {
        pre[i] = max(v[i], pre[i - 1]);
        if(pre[i] == pre[i - 1]) {
            prel[i] = prel[i - 1];
        } else {
            prel[i] = i;
        }
    }
    suf[n - 1] = v[n - 1];
    sufr[n - 1] = n - 1;
    for(int i = n - 2; i >= 0; i--) {
        suf[i] = max(v[i], suf[i + 1]);
        if(suf[i] == suf[i + 1]) {
            sufr[i] = sufr[i + 1];
        } else {
            sufr[i] = i;
        }
    }
    int l = prel[n - 1], r = sufr[0];
    taken[l] = taken[r] = 1;
    l--, r++;
    while(l >= 0) {
        l = prel[l];
        taken[l] = 1;
        l--;
    }
    while(r <= n - 1) {
        r = sufr[r];
        taken[r] = 1;
        r++;
    }
    ll ans = 0;
    int previdx = -1;
    for(int i = 0; i < n; i++) {
        if(taken[i] == 0) {
            continue;
        }
        if(previdx == -1) {
            previdx = i;
        } else {
            ll cur = 1LL * (i - previdx) * (v[i] + v[previdx]);
            ans = (ans + cur);
            previdx = i;
        }
    }
    cout << ans << "\n";
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int tc = 1;
    cin >> tc;
    while(tc--) {
        test_case();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 196ms
memory: 4256kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
381268324603
658930892444
543073796232
458946673513
296420749955
872966641760
630432425409
583595848800
225238172692
715347519911
462034667948
273545943459
585094154153
200443831314
336548821022
483213442818
602558460217
586771956643
400264139273
826365121407
975377092201
920978353624
26408806...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '381268324603'