「考前日志」11.10


自己干了什么還是可視化一點比較好。
不然什么也沒干還裝作自己過得很充實
從今天開始寫吧。
濤哥

總結

媽的頹了一天就做了仨題
這考前日志都發不出手了
明天會變好的對吧……
但是紅貝貝的Psycho真的好好聽啊/kk

上午

賢者時間從未停止……
一上午就一道題
嚶嚶嚶

洛谷 P4291 [HAOI2008]排名系統

輸入的處理比較惡心。
暴力可以直接sort比較然后輸出。
正解的話可以用平衡樹,但是我不會了,所以用了線段樹。

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;

const int A = 3e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

int n;
struct dat {
  int soc, tim;
  string nam;
  char opt;
  inline bool operator < (const dat &tmp) const {
    return soc != tmp.soc ? soc<tmp.soc : tim>tmp.tim;
  }
} c[A], d[A];
map <string, int> pre;
int t[A << 2], pos, val, res;

void update(int rt, int l, int r) {
  t[rt] += val;
  if (l == r) return;
  int mid = l + r >> 1;
  if (pos <= mid) update(lson, l, mid);
  else update(rson, mid + 1, r);
}

void query_rnk(int rt, int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  if (pos <= mid) query_rnk(lson, l, mid), res += t[rson];
  else query_rnk(rson, mid + 1, r);
}

void query(int rt, int l, int r) {
  if (l == r) {
    res = l;
    return;
  }
  int mid = l + r >> 1;
  if (val > t[rson]) val -= t[rson], query(lson, l, mid);
  else query(rson, mid + 1, r);
}

inline int calc(string s) {
  int m = s.size(), res = 0;
  for (int i = 0; i < m; i++)
    res = res * 10 + s[i] - '0';
  return res;
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    cin >> d[i].opt >> d[i].nam;
    if (d[i].opt == '+') d[i].soc = read();
    d[i].tim = i, c[i] = d[i];
  }
  sort(d + 1, d + n + 1);
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i].opt == '+') {
      pos = pre[c[i].nam];
      if (pos) val = -1, update(1, 1, n);
      else tot++;
      pos = lower_bound(d + 1, d + n + 1, c[i]) - d;
      val = 1;
      update(1, 1, n);
      pre[c[i].nam] = pos;
      continue;
    }
    if (c[i].nam[0] > '9' || c[i].nam[0] < '0') {
      res = 0;
      pos = pre[c[i].nam];
      query_rnk(1, 1, n);
      cout << res + 1 << '\n';
      continue;
    }
    for (int k = 1, j = calc(c[i].nam); k <= 10 && j <= tot; k++, j++) {
      val = j, res = 0;
      query(1, 1, n);
      cout << d[res].nam << " ";
    }
    puts("");
  }
  return 0;
}

/*
暴力做法?
簡直不能再暴力了 
直接sort 
*/
/* 
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 3e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

int n, cnt;
string nam;
struct node {
  int tim, sco;
  string name;
} a[A];

bool cmp(node x, node y) {
  return x.sco != y.sco ? x.sco > y.sco : x.tim < y.tim;
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    sort(a + 1, a + 1 + cnt, cmp);
    char c;
    cin >> c;
    if (c == '+') {
      cin >> nam;
      int scor = read(), flag = 0;
      for (int j = 1; j <= cnt; j++) {
        if (a[j].name == nam) {
          a[j] = (node) {i, scor, nam};
          flag = 1;
          break;
        }
      }
      if (!flag) a[++cnt] = (node){i, scor, nam};
    }
    else {
      nam = "";
      char c = getchar();
      if (isdigit(c)) {
        int x = 0;
        for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
        for (int j = x; j <= min(cnt, x + 9); j++) {
          cout << a[j].name << " ";
        } 
        puts("");
      }
      else {
        cin >> nam;
        nam = c + nam;
        for (int j = 1; j <= cnt; j++) {
          if (a[j].name == nam) {
            cout << j << '\n';
            break;
          }
        }
      }
    }
  }
  return 0;
}
*/

下午

洛谷 P4903 心碎

隨即跳題跳到了這個找規律題……猜了幾遍結論A了,然而並不懂做法/kk

題目中有一句話很關鍵:\(i<A_i\) 時為順時針,\(i>A_i\) 時逆時針,\(i=A_i\) 時正對應

然后畫出了很鬼畜的樣例圖。。。

#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

signed main() {
  int x = read();
  cout << (x * x) / 2 + 1; 
}

晚上

學DP 算法競賽進階指南nb/se
這里


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM