Submission #553431

#TimeUsernameProblemLanguageResultExecution timeMemory
553431AugustinasJucasMatching (CEOI11_mat)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("avx2") using namespace std; int n, m; vector<int> a, b; const int mod = 1e9 + 7; const long long maxN = 1000000 ; const int dydis = 1e6 + 10; vector<long long> pw; struct treap { int dbInd = 0; vector<int> l, r, w; vector<int> val, myInd, sz; vector<int> subHash; int rt = -1; treap() { pw.resize(dydis); l.resize(dydis); r.resize(dydis); w.resize(dydis); val.resize(dydis); myInd.resize(dydis); subHash.resize(dydis); sz.resize(dydis); pw[0] = 1; for(int i = 1; i < dydis; i++) { pw[i] = 1ll * pw[i-1] * maxN % mod; } } int newN(int Val, int Ind){ l[dbInd] = r[dbInd] = -1; w[dbInd] = rand(); val[dbInd] = Val; myInd[dbInd] = Ind; subHash[dbInd] = Ind; sz[dbInd] = 1; return dbInd++; } int hMerge(int h1, int h2, int sz2){ int ret = h1; ret = 1ll * ret * pw[sz2] % mod; ret = (ret + h2) % mod; return ret; } void upd(int v){ int hashL = 0, hashR = 0, hashMid; int lsz = 0; int rsz = 0; if(l[v] != -1) { hashL = subHash[l[v]]; lsz = sz[l[v]]; } if(r[v] != -1) { hashR = subHash[r[v]]; rsz = sz[r[v]]; } hashMid = myInd[v]; sz[v] = lsz + 1 + rsz; subHash[v] = (1ll*hashL * maxN%mod + hashMid)%mod; subHash[v] = hMerge(subHash[v], hashR, rsz); } pair<int, int> split(int v, int vl) { if(v == -1) return {-1, -1}; if(val[v] < vl) { // as kaireje puseje auto ds = split(r[v], vl); r[v] = ds.first; upd(v); return {v, ds.second}; }else { // as desineje puseje auto kr = split(l[v], vl); l[v] = kr.second; upd(v); return {kr.first, v}; } } int merge(int L, int R) { if(R == -1) return L; if(L == -1) return R; if(w[L] > w[R]) { int mr = merge(r[L], R); r[L] = mr; upd(L); return L; }else { int mr = merge(L, l[R]); l[R] = mr; upd(R); return R; } } void print(int v = -2){ if(v == -2) v = rt; if(v == -1) return ; print(l[v]); cout << "(val=" << val[v] << ", ind=" << myInd[v] << ") "; print(r[v]); } void insert(int val, int ind) { int nd = newN(val, ind); auto prm = split(rt, val); prm.first = merge(prm.first, nd); rt = merge(prm.first, prm.second); // cout << "rt tampa " << rt << endl; } void erase(int val) { auto prm = split(rt, val+1); auto ant = split(prm.first, val); rt = merge(ant.first, prm.second); } int getHash() { return subHash[rt]; } }; treap medis; int main () srand(time(0)); cin.tie(NULL); ios_base::sync_with_stdio(false); /*int sk = 5; int indd = 0; while(sk--) { int val, ind; cin >> val ; medis.insert(val, indd++); medis.print(); cout << ", bendras hashas = " << medis.getHash(); cout << endl; } sk = 5; while(sk--) { int val, ind; cin >> val; medis.erase(val, 0); medis.print(); //cout << ", bendras hashas = " << medis.getHash(); //cout << endl; }*/ cin >> n >> m; a.resize(n); b.resize(m); for(int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for(auto &x : b) { cin >> x; } long long reikia = 0; for(auto x : a) { reikia = (1ll * reikia * maxN % mod + x) % mod; } //cout << "reikia = " << reikia << endl; for(int i = 0; i < n; i++) { medis.insert(b[i], i); } long long turi = 0; for(int i = 0; i < n; i++) { turi = (turi + pw[i]) % mod; } vector<int> ans; if(medis.getHash() == reikia) { ans.push_back(0); } for(int i = n; i < m; i++) { medis.erase(b[i-n]); medis.insert(b[i], i); int hsh = ((medis.getHash() - 1ll * (i-n+1) * turi % mod) % mod + mod) % mod; if(reikia == hsh) { ans.push_back(i-n+1); } // cout << "nuo " << i << ", hsh = " << hsh << endl; } cout << ans.size() << "\n"; for(auto &x : ans) { cout << x+1 << " "; } return 0; } /* 5 10 2 1 5 3 4 5 6 3 8 12 7 1 10 11 9 2 5 1 2 1 2 3 4 5 */

Compilation message (stderr)

mat.cpp:118:2: error: expected initializer before 'srand'
  118 |  srand(time(0));
      |  ^~~~~
mat.cpp:119:2: error: 'cin' does not name a type; did you mean 'sin'?
  119 |  cin.tie(NULL);
      |  ^~~
      |  sin
mat.cpp:120:27: error: expected constructor, destructor, or type conversion before '(' token
  120 |  ios_base::sync_with_stdio(false);
      |                           ^
mat.cpp:141:2: error: 'cin' does not name a type; did you mean 'sin'?
  141 |  cin >> n >> m;
      |  ^~~
      |  sin
mat.cpp:142:2: error: 'a' does not name a type
  142 |  a.resize(n);
      |  ^
mat.cpp:143:2: error: 'b' does not name a type
  143 |  b.resize(m);
      |  ^
mat.cpp:144:2: error: expected unqualified-id before 'for'
  144 |  for(int i = 0; i < n; i++) {
      |  ^~~
mat.cpp:144:17: error: 'i' does not name a type
  144 |  for(int i = 0; i < n; i++) {
      |                 ^
mat.cpp:144:24: error: 'i' does not name a type
  144 |  for(int i = 0; i < n; i++) {
      |                        ^
mat.cpp:148:2: error: expected unqualified-id before 'for'
  148 |  for(auto &x : b) {
      |  ^~~
mat.cpp:152:2: error: expected unqualified-id before 'for'
  152 |  for(auto x : a) {
      |  ^~~
mat.cpp:156:2: error: expected unqualified-id before 'for'
  156 |  for(int i = 0; i < n; i++) {
      |  ^~~
mat.cpp:156:17: error: 'i' does not name a type
  156 |  for(int i = 0; i < n; i++) {
      |                 ^
mat.cpp:156:24: error: 'i' does not name a type
  156 |  for(int i = 0; i < n; i++) {
      |                        ^
mat.cpp:160:2: error: expected unqualified-id before 'for'
  160 |  for(int i = 0; i < n; i++) {
      |  ^~~
mat.cpp:160:17: error: 'i' does not name a type
  160 |  for(int i = 0; i < n; i++) {
      |                 ^
mat.cpp:160:24: error: 'i' does not name a type
  160 |  for(int i = 0; i < n; i++) {
      |                        ^
mat.cpp:164:2: error: expected unqualified-id before 'if'
  164 |  if(medis.getHash() == reikia) {
      |  ^~
mat.cpp:167:2: error: expected unqualified-id before 'for'
  167 |  for(int i = n; i < m; i++) {
      |  ^~~
mat.cpp:167:17: error: 'i' does not name a type
  167 |  for(int i = n; i < m; i++) {
      |                 ^
mat.cpp:167:24: error: 'i' does not name a type
  167 |  for(int i = n; i < m; i++) {
      |                        ^
mat.cpp:176:2: error: 'cout' does not name a type
  176 |  cout << ans.size() << "\n";
      |  ^~~~
mat.cpp:177:2: error: expected unqualified-id before 'for'
  177 |  for(auto &x : ans) {
      |  ^~~
mat.cpp:180:2: error: expected unqualified-id before 'return'
  180 |  return 0;
      |  ^~~~~~
mat.cpp:181:1: error: expected declaration before '}' token
  181 | }
      | ^