제출 #1106125

#제출 시각아이디문제언어결과실행 시간메모리
1106125underwaterkillerwhaleMatching (CEOI11_mat)C++17
9 / 100
72 ms65536 KiB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e6 + 2;
const int Mod = 1e6 + 3;///lon
const int INF = 1e9 + 7;
const ll BASE = 137;
const int szBL = 350;

int n, m;
int a[2 * N];
int pw[N];

struct Segment_Tree {
    int m;
    pii st[N << 3];

    void init (int n) {
        m = n;
    }

    void update (int id, int l, int r, int pos, int val) {
        if (l > pos || r < pos) return;
        if (l == r) {
            if (val == 0) st[id] = MP(0, 0);
            else st[id] = MP(val, 1);
            return;
        }
        int mid = l + r >> 1;
        update (id << 1, l, mid, pos, val);
        update (id << 1 | 1, mid + 1, r, pos, val);
        st[id].fs = (1LL * st[id << 1].fs * pw[st[id << 1 | 1].se] % Mod + st[id << 1 | 1].fs) % Mod;
        st[id].se = st[id << 1].se + st[id << 1 | 1].se;
    }
    void update (int pos, int val) {
        update (1, 1, m, pos, val);
    }
}ST;

void solution () {
    cin >> n >> m;
    rep (i, 1, n) cin >> a[i];
    rep (i, n + 1, n + m) {
        cin >> a[i];
        a[i] += n;
    }
    auto compress = [&] () {
        vector<int> vals;
        rep (i, 1, n + m) vals.pb(a[i]);
        sort(ALL(vals));
        rep (i, 1, n + m) {
            a[i] = lower_bound(ALL(vals), a[i]) - vals.begin();
        }
    };
    compress();

    int curHs = 0, sum = 0;
    pw[0] = 1;
    rep (i, 1, n) {
        curHs = (1LL * curHs * BASE % Mod + a[i]) % Mod;
        pw[i] = 1LL * pw[i - 1] * BASE % Mod;
        sum = (sum + pw[i - 1]) % Mod;
    }
    map<int, bool> dd;
    dd[curHs] = 1;
    rep (i, 1, n + m) {
        curHs = (curHs + sum) % Mod;
        dd[curHs] = 1;
    }

    ST.init(n + m);
    vector<int> Ans;
    rep (i, n + 1, n + n) {
        ST.update (a[i], i);
    }
    if (dd[ST.st[1].fs]) Ans.pb(n + 1);
    rep (i, n + n + 1, n + m) {
        ST.update (a[i - n], 0);
        ST.update (a[i], i);
        if (dd[ST.st[1].fs]) Ans.pb(i - n + 1);
    }
    cout << SZ(Ans) <<"\n";
    iter (&id, Ans) cout << id - n <<" ";

}

#define file(name) freopen(name".inp","r",stdin); freopen(name".out","w",stdout);
main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +13
*/

컴파일 시 표준 에러 (stderr) 메시지

mat.cpp: In member function 'void Segment_Tree::update(int, int, int, int, int)':
mat.cpp:46:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         int mid = l + r >> 1;
      |                   ~~^~~
mat.cpp: At global scope:
mat.cpp:105:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  105 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...