做题记录

Posted foreverpiano

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了做题记录相关的知识,希望对你有一定的参考价值。

今天的题目画风诡异 于是就不写详细写题解了.. 简单说一下吧

t1 是平衡树维护哈希值
我之前看过用线段树维护哈希值得
然后那题没有去补 于是这题就爆炸了
最后暴力还写挂了 吃枣药丸

t2 正解是基环外向树同构什么的 但是可以特判过去
我写了暴力 没写挂 但是CE了..

t3 提交答案题
爆搜 + 构造
暴力多跑一会儿就有30pts
跑出了一个很优秀的答案 (比标算还优秀
然后稍微构造一下就ac了.
构造还挺巧妙的
首先多加一行 可行的范围扩到\(2n + 1\)
然后考虑变成\(3n + 1\)
就是把之前复制一份 然后加上\(2n+1\)
容易证明是正确的
于是就是正确的

t1

#include<bits/stdc++.h>
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
#define P pair<int, int>
#define MP make_pair
#define fi first
#define se second
const int mo1 = 1e9 + 7;
const int b1 = 167;
const int b2 = 13;
const int mo2 = 1e4 + 7;
const int N = 2e6 + 233;
  
int sa = 0, L[N], R[N], rev[N], h[N], t[N], w[N], fix[N], sz[N], rt;
int n, m, a[N], b[N], s1, s2, s3, s4, Base[N], ha1[N];
int B[N], ha2[N], h1[N], t1[N];
char str[233];
  
inline int nw(int val) {
  ++ sa;
  L[sa] = R[sa] = rev[sa] = 0;
  h[sa] = t[sa] = w[sa] = h1[sa] = t1[sa] = val;
  fix[sa] = rand();
  sz[sa] = 1;
  return sa;
}
 
inline void pd(int x) {
  if(rev[x]) {
    swap(L[x], R[x]);
    swap(h[x], t[x]);
    swap(h1[x], t1[x]);
    if(L[x]) rev[L[x]] ^= 1;
    if(R[x]) rev[R[x]] ^= 1;
    rev[x] = 0;
  }
}
 
inline void ps(int x) {
  if(L[x]) pd(L[x]);
  if(R[x]) pd(R[x]);
  int ls = L[x], rs = R[x];
  sz[x] = sz[ls] + sz[rs] + 1;
  int lz = sz[ls];
  int rz = sz[rs];
  h[x] = (1ll * w[x] * Base[rz] % mo1 + 1ll * h[ls] * Base[rz + 1] % mo1 + h[rs]) % mo1;
  t[x] = (1ll * w[x] * Base[lz] % mo1 + 1ll * t[rs] * Base[lz + 1] % mo1 + t[ls]) % mo1;
  h1[x] = (1ll * w[x] * B[rz] % mo2 + 1ll * h1[ls] * B[rz + 1] % mo2 + h1[rs]) % mo2;
  t1[x] = (1ll * w[x] * B[lz] % mo2 + 1ll * t1[rs] * B[lz + 1] % mo2 + t1[ls]) % mo2;
}
  
inline int make(int x, int y) {
  if(!x || !y) return x | y;
  if(fix[x] < fix[y]) {
    pd(x);
    R[x] = make(R[x], y);
    ps(x);
    return x;
  }
  else {
    pd(y);
    L[y] = make(x, L[y]);
    ps(y);
    return y;
  }
}
  
inline P split(int x, int k) {
  if(!x) return MP(0, 0);
  P y;
  pd(x);
  int s = (L[x] ? sz[L[x]] : 0);
  if(s <= k - 1) {
    y = split(R[x], k - s - 1);
    R[x] = y.fi;
    ps(x);
    y.fi = x;
  }
  else {
    y = split(L[x], k);
    L[x] = y.se;
    ps(x);
    y.se = x;
  }
  return y;
}
  
inline void ins(int pos, int val) {
  P x = split(rt, pos - 1);
  rt = make(make(x.fi, nw(val)), x.se);
  ++ n;
}
  
inline void del(int pos) {
  P x = split(rt, pos - 1), y = split(x.se, 1);
  rt = make(x.fi, y.se);
  -- n;
}
  
inline void Rever(int l, int r) {
  if(l > r) swap(l, r);
  P x = split(rt, l - 1);
  P y = split(x.se, r - l + 1);
  rev[y.fi] ^= 1;
  rt = make(make(x.fi, y.fi), y.se);
}
  
inline void ha(int *b, int *ha1, int *ha2, int n) {
  ha1[0] = 0; ha2[0] = 0;
  for(int i = 1; i <= n; i ++) {
    ha1[i] = (1ll * ha1[i - 1] * b1 + b[i]) % mo1;
    ha2[i] = (1ll * ha2[i - 1] * b2 + b[i]) % mo2;
  }
}
  
inline int fac(int a, int b) {
  if(a == mo1) return Base[b];
  else return B[b];
}
  
inline P Getval(int l, int r) {
  P x = split(rt, l - 1), y = split(x.se, r - l + 1);
  P ans = MP(h[y.fi], h1[y.fi]);
  rt = make(x.fi, make(y.fi, y.se));
  return ans;
}
  
inline int check(int now, int s, int t) {
  int m = t + now - 1;
  int b = (ha1[m] - 1ll * ha1[t - 1] * fac(mo1, now) % mo1 + mo1) % mo1;
  int b2 = (ha2[m] - 1ll * ha2[t - 1] * fac(mo2, now) % mo2 + mo2) % mo2;
  P a = Getval(s, s + now - 1);
  return a.fi == b && a.se == b2;
}
  
inline int doit(int s, int t) {
  int l = 0, r = min(n - s + 1, m - t + 1);
  while(l < r) {
    int mid = l + (r - l + 1) / 2;
    if(check(mid, s, t)) l = mid;
    else r = mid - 1;
  }
  return l;
}
  
main(void) {
  srand(20021214);
  Base[0] = 1; B[0] = 1;
  for(int i = 1; i <= N - 10; i ++) {
    Base[i] = (1ll * Base[i - 1] * b1) % mo1;
    B[i] = (1ll * B[i - 1] * b2) % mo2;
  }
  read(n); read(m);
  for(int i = 1; i <= n; i ++)
    read(a[i]), rt = make(rt, nw(a[i]));
  for(int i = 1; i <= m; i ++)
    read(b[i]);
  b[m + 1] = 23333;
  ha(b, ha1, ha2, m);
  read(s1); read(s2); read(s3); read(s4);
  int all = s1 + s2 + s3 + s4;
  for(int i = 1; i <= all; i ++) {
    int l, r, k, p;
    scanf("%s", str);
    if(str[0] == 'Q') {
      read(l); read(r);
      cout << doit(l, r) << "\n";
    }
    if(str[0] == 'I') {
      read(k); read(p);
      ins(k, p);
    }
    if(str[0] == 'D') {
      read(k); del(k);
    }
    if(str[0] == 'R') {
      read(l); read(r);
      Rever(l, r);
    }
  }
}

t2

#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
const int N = 32;
int n, b[N], c[N], a[N];
map<long long, int> mp;
long long fac[N];
inline void O(__int128 n) {
  if(!n) return ;
  O(n / 10); cout << (int) (n % 10);
}
main(void) {
  read(n);
  if(n >= 12) {
    __int128 ans = 1;
    for(int i = 1; i <= n; i ++)
      ans *= i;
    if(n == 21) ans /= 2;
    else if(n == 18 || n == 27) ans /= 4;
    else if(n == 24) ans /= 32;
    O(ans);
    return 0;
  }
  for(int i = 1; i <= n; i ++)
    read(c[i]);
  for(int i = 1; i <= n; i ++)
    b[i] = i;
  do {
    for(int i = 1; i <= n; i ++)
      a[b[i]] = b[c[i]];
    long long t = 0;
    for(int i = 1; i <= n; i ++)
      t = 1ll * t * 10 + a[i];
    mp[t] = 1;
  } while(next_permutation(b + 1, b + n + 1));
  cout << mp.size() << "\n";
}

t3

#include<bits/stdc++.h>
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
int n;
string str;
main(void) {
  freopen("regulation9.out", "r", stdin);
  freopen("regulation10.out", "w", stdout);
  read(n);
  cout << 3 * n + 1 << "\n";
  for(int i = 1; i <= 12; i ++) {
    getline(cin, str);
    cout << str;
    int now = 0;
    for(int k = 0; k < str.length(); k ++) {
      if(str[k] == ' ') {
        cout << now + 2 * n + 1 << " ";
        now = 0;
      }
      else now = now * 10 + str[k] - '0';
    }
    puts("");
  }
  for(int i = n + 1; i <= 2 * n + 1; i ++)
    cout << i << " ";
  puts("");
}

构造的初始数据

135
6 9 10 14 21 22 26 38 39 50 51 54 62 66 67 69 70 74 82 85 86 97 98 114 115 122 126 127 130 
3 13 19 24 25 29 30 31 35 40 41 45 47 52 57 68 79 84 89 91 95 96 100 101 105 106 107 111 112 117 133 
2 8 11 15 32 36 37 42 46 55 56 59 60 76 77 80 81 90 94 99 103 104 121 124 125 128 
4 7 12 17 18 27 28 33 43 48 49 58 63 64 72 73 78 87 88 93 108 109 118 119 129 132 134 
1 5 16 20 23 34 44 53 61 65 71 75 83 92 102 110 113 116 120 123 131 135 

以上是关于做题记录的主要内容,如果未能解决你的问题,请参考以下文章

ARC的F 做题记录

算法竞赛入门经典训练指南-做题详细记录(更新中)

做题记录:P2827 蚯蚓

noip做题记录+挑战一句话题解?

2021年11月的做题记录

第九届蓝桥杯省赛B组 做题记录(python)