AtCoder Regular Contest 069

Submission #1120542

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  ll n;
  scanf("%lld", &n);
  vll a(n);
  vvll positive;
  positive.reserve(n);
  ll current_max = 0;
  set<int> indexes;
  rep (i, n) {
    scanf("%lld", &a[i]);
    if (current_max < a[i]) {
      positive.push_back((vll){a[i], (ll)i});
      indexes.insert(i);
      current_max = a[i];
    }
  }
  int sz = (int)positive.size();

  vvll column_total(sz, vll(2, (ll)0));
  vll ans(n, (ll)0);
  for (int i = n-1; i >= 0; --i) {
    int lb = lower_bound(all(positive), (vll){a[i]}) - begin(positive);
    if (indexes.find(i) == end(indexes)) {
      column_total[lb][0] += 1;
      column_total[lb][1] += a[i];
    } else if (lb > 0) {
      column_total[lb][0] += 1;
      column_total[lb][1] += a[i];
      ans[positive[lb][1]] = column_total[lb][1] - column_total[lb][0] * positive[lb-1][0];
      column_total[lb-1][0] += column_total[lb][0];
      column_total[lb-1][1] += column_total[lb][0] * positive[lb-1][0];
    } else {
      ans[0] = column_total[0][1] + a[0];
    }
  }
  rep (i, n) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}

Submission

Task問題 E - Frequency
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 700
Source lengthソースコード長 1999 Byte
File nameファイル名
Exec time実行時間 76 ms
Memory usageメモリ使用量 18048 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt
All 700 / 700 00_example_01.txt,00_example_02.txt,01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,31.txt,32.txt,33.txt,34.txt,35.txt,36.txt,37.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
01.txt AC 1 ms 256 KB
02.txt AC 2 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 3 ms 384 KB
10.txt AC 1 ms 256 KB
11.txt AC 22 ms 2048 KB
12.txt AC 22 ms 2048 KB
13.txt AC 22 ms 2048 KB
14.txt AC 21 ms 2048 KB
15.txt AC 22 ms 2048 KB
16.txt AC 23 ms 2048 KB
17.txt AC 76 ms 18048 KB
18.txt AC 22 ms 2048 KB
19.txt AC 18 ms 2048 KB
20.txt AC 22 ms 2048 KB
21.txt AC 1 ms 256 KB
22.txt AC 1 ms 256 KB
23.txt AC 1 ms 256 KB
24.txt AC 4 ms 896 KB
25.txt AC 1 ms 256 KB
26.txt AC 1 ms 256 KB
27.txt AC 1 ms 256 KB
28.txt AC 70 ms 16128 KB
29.txt AC 71 ms 16896 KB
30.txt AC 76 ms 18048 KB
31.txt AC 71 ms 16256 KB
32.txt AC 70 ms 16128 KB
33.txt AC 21 ms 2048 KB
34.txt AC 21 ms 2048 KB
35.txt AC 21 ms 2048 KB
36.txt AC 21 ms 2048 KB
37.txt AC 21 ms 2048 KB