結果

問題 No.318 学学学学学
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-01-02 12:20:01
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,564 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 63,124 KB
最終ジャッジ日時 2024-11-14 19:31:57
合計ジャッジ時間 1,217 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:14:3: error: ‘vector’ does not name a type
   14 |   vector<i64> seg, lazy;
      |   ^~~~~~
main.cpp: In member function ‘void Segtree::push(int, int, int)’:
main.cpp:28:6: error: ‘lazy’ was not declared in this scope
   28 |   if(lazy[k] == -1) { return; }
      |      ^~~~
main.cpp:29:3: error: ‘seg’ was not declared in this scope
   29 |   seg[k] = lazy[k] * (r-l);
      |   ^~~
main.cpp:29:12: error: ‘lazy’ was not declared in this scope
   29 |   seg[k] = lazy[k] * (r-l);
      |            ^~~~
main.cpp: In member function ‘void Segtree::update(int, int, i64, int, int, int)’:
main.cpp:45:5: error: ‘lazy’ was not declared in this scope
   45 |     lazy[k] = val;
      |     ^~~~
main.cpp:51:3: error: ‘seg’ was not declared in this scope
   51 |   seg[k] = merge(seg[k*2+1], seg[k*2+2]);
      |   ^~~
main.cpp: In member function ‘i64 Segtree::query(int, int, int, int, int)’:
main.cpp:57:35: error: ‘seg’ was not declared in this scope
   57 |   if(lo <= l && r <= hi) { return seg[k]; }
      |                                   ^~~
main.cpp: In constructor ‘Segtree::Segtree(int)’:
main.cpp:65:3: error: ‘seg’ was not declared in this scope
   65 |   seg.resize(size*2);
      |   ^~~
main.cpp:66:3: error: ‘lazy’ was not declared in this scope
   66 |   lazy.assign(size*2, -1);
      |   ^~~~
main.cpp: In function ‘int main()’:
main.cpp:77:3: error: ‘vector’ was not declared in this scope
   77 |   vector<int> a(n);
      |   ^~~~~~
main.cpp:4:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    3 | #include <map>
  +++ |+#include <vector>
    4 | using namespace std;
main.cpp:77:10: error: expected primary-expression before ‘int’
   77 |   vector<int> a(n);
      |          ^~~
main.cpp:81:18: error: ‘a’ was not declared in this scope
   81 |     scanf("%d", &a[i]);
      |                  ^
main.cpp:85:10: error: ‘a’ was not d

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
using i64 = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

///
class Segtree {
private:
  int size;
  vector<i64> seg, lazy;
  void push(int k, int l, int r);
  i64 merge(i64 x, i64 y);
  void update(int lo, int hi, i64 val, int k, int l, int r);
  i64 query(int lo, int hi, int k, int l, int r);
public:
  Segtree(int n);
  void update(int lo, int hi, i64 val); // [lo, hi)
  void update(int i, i64 val);
  i64 query(int lo, int hi); // [lo, hi)
  i64 query(int i);
};

void Segtree::push(int k, int l, int r) {
  if(lazy[k] == -1) { return; }
  seg[k] = lazy[k] * (r-l);
  if(r-l > 1) {
    lazy[k*2+1] = lazy[k];
    lazy[k*2+2] = lazy[k];
  }
  lazy[k] = -1;
}

i64 Segtree::merge(i64 x, i64 y) {
  return x + y;
}

void Segtree::update(int lo, int hi, i64 val, int k, int l, int r) {
  push(k, l, r);
  if(r <= lo || hi <= l) { return; }
  if(lo <= l && r <= hi) {
    lazy[k] = val;
    push(k, l, r);
    return;
  }
  update(lo, hi, val, k*2+1, l, (l+r)/2);
  update(lo, hi, val, k*2+2, (l+r)/2, r);
  seg[k] = merge(seg[k*2+1], seg[k*2+2]);
}

i64 Segtree::query(int lo, int hi, int k, int l, int r) {
  push(k, l, r);
  if(r <= lo || hi <= l) { return 0; }
  if(lo <= l && r <= hi) { return seg[k]; }
  i64 x = query(lo, hi, k*2+1, l, (l+r)/2),
      y = query(lo, hi, k*2+2, (l+r)/2, r);
  return merge(x, y);
}

Segtree::Segtree(int n) {
  for(size=1; size<n; size*=2) ;
  seg.resize(size*2);
  lazy.assign(size*2, -1);
}

void Segtree::update(int lo, int hi, i64 val) { update(lo, hi, val, 0, 0, size); }
void Segtree::update(int i, i64 val) { update(i, i+1, val, 0, 0, size); }
i64 Segtree::query(int lo, int hi) { return query(lo, hi, 0, 0, size); }
i64 Segtree::query(int i) { return query(i, i+1, 0, 0, size); }
///

int main(void) {
  int n; scanf("%d", &n);
  vector<int> a(n);
  map<int, int> left, rght;
  Segtree tree(n);
  for(int i : range(n)) {
    scanf("%d", &a[i]);
    tree.update(i, a[i]);
  }
  for(int i : range(n)) {
    rght[a[i]] = i;
    left[a[n-1-i]] = n-1-i;
  }
  for(auto kv : left) {
    int val, pos; tie(val, pos) = kv;
    if(!rght.count(val)) { continue; }
    tree.update(pos, rght[val]+1, val);
  }
  for(int i : range(n)) {
    if(i) { putchar(' '); }
    printf("%d", int(tree.query(i)));
  }
  putchar('\n');
  return 0;
}
0