Forever Young

「考前日志」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
这里

posted @ 2020-11-10 07:30  Loceaner  阅读(97)  评论(10编辑  收藏  举报