快读
char buf[1<<15],*fs,*ft;
inline char getc(){
return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:* fs++;
}
inline int read(){
int This=0,F=1; char ch=getc();
while(ch<'0'||ch>'9'){
if(ch=='-') F=-1;
ch=getc();
}
while(ch>='0'&&ch<='9'){
This=(This<<1)+(This<<3)+ch-'0';
ch=getc();
}
return This*F;
}
pbds
hash表
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
struct splitmix64 {
size_t operator()(size_t x) const {
static const size_t fixed = chrono::steady_clock::now().time_since_epoch().count();
x += 0x9e3779b97f4a7c15 + fixed;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
};
// 探测法
gp_hash_table<int,int,splitmix64> f;
// 拉链法
cc_hash_table<int,int,splitmix64> f;
树
// __gnu_pbds::tree<Key,T>
// 当set用的话 T设置为nulltype即可
// begin(),end(),size(),empty(),clear(),find(const key), lower_bound(const key),upper_bound(const key),erase(iterator),erase(const key),insert(const pair<Key,T>), operator[](const Key)用法与map相同
// order_of_key 查询有多少个小于key的元素
// find_by_order 查询第order+1的元素,太大返回end()
// void(tree &other) 把other中所有元素移到*this中
// a.split(v, b) key <= v的属于a,其他属于b
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
__gnu_pbds::tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> T;
int n; cin >> n;
for(int i = 1 ; i <= n ; i ++)
{
ll opt,x; cin >> opt >> x;
switch(opt)
{
case 1:T.insert((x<<20)+i); break;
case 2:T.erase(T.lower_bound(x<<20)); break;
case 3:cout << T.order_of_key(x<<20)+1 << '\n';break;
case 4:cout << ((*T.find_by_order(x-1))>>20) << '\n';break;
case 5:cout << ((*(--T.lower_bound(x<<20)))>>20) << '\n';break;
case 6:cout << ((*T.upper_bound((x<<20)+n))>>20) << '\n';break;
}
}
}
2 SAT
struct TwoSat {
int n;
std::vector<std::vector<int>> e;
std::vector<bool> ans;
TwoSat(int n) : n(n), e(2 * n), ans(n) {}
void addClause(int u, bool f, int v, bool g) {
e[2 * u + !f].push_back(2 * v + g);
e[2 * v + !g].push_back(2 * u + f);
}
bool satisfiable() {
std::vector<int> id(2 * n, -1), dfn(2 * n, -1), low(2 * n, -1);
std::vector<int> stk;
int now = 0, cnt = 0;
std::function<void(int)> tarjan = [&](int u) {
stk.push_back(u);
dfn[u] = low[u] = now++;
for (auto v : e[u]) {
if (dfn[v] == -1) {
tarjan(v);
low[u] = std::min(low[u], low[v]);
} else if (id[v] == -1) {
low[u] = std::min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
int v;
do {
v = stk.back();
stk.pop_back();
id[v] = cnt;
} while (v != u);
++cnt;
}
};
for (int i = 0; i < 2 * n; ++i) if (dfn[i] == -1) tarjan(i);
for (int i = 0; i < n; ++i) {
if (id[2 * i] == id[2 * i + 1]) return false;
ans[i] = id[2 * i] > id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return ans; }
};