• cf896C. Willem, Chtholly and Seniorious(ODT)


    题意

    题目链接

    Sol

    ODT板子题。就是用set维护连续段的大暴力。。

    然鹅我抄的板子本题RE提交AC??。。

    具体来说,用50 50 658073485 946088556这个数据测试下面的代码,然后在79行停住,看一下bg和i的值会发生神奇的事情。。

    问题已解决,确实是那位博主写错了, 只要把split(l)和split(r + 1)反过来就行了

    #include<bits/stdc++.h>
    #define LL long long 
    #define int long long 
    #define sit set<Node>::iterator 
    #define fi first
    #define se second 
    using namespace std;
    const int MOD = 1e9 + 7, MAXN = 1e6 + 10;
    inline int read() {
    	char c = getchar(); int x = 0, f = 1;
    	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return x * f;
    }
    int N, M, mod;
    template<typename A, typename B> inline int mul(A x, B y) {
    	return 1ll * x * y % mod;
    }
    template<typename A, typename B> inline void add2(A &x, B y) {
    	x = (x + y % mod);
    }
    LL seed, vmax;
    int a[MAXN];
    int rnd() {
    	int ret = seed;
    	seed = (seed * 7 + 13) % MOD;
    	return ret;
    }
    struct Node {
    	int l, r;
    	mutable LL v;
    	bool operator < (const Node &rhs) const {
    		return l < rhs.l;
    	}
    };
    set<Node> s;
    sit split(int p) {
    	auto pos = s.lower_bound({p});
    	if(pos != s.end() && pos->l == p) return pos; 
    	pos--;
    	int L = pos->l, R = pos->r, V = pos->v;
    	s.erase(pos);
    	s.insert({L, p - 1, V}); 
    	return s.insert({p, R, V}).fi;
    }
    void Add(int l, int r, int val) {
    	auto bg = split(l), ed = split(r + 1);
    	for(auto i = bg; i != ed; i++) i->v += val;
    }
    void Mem(int l, int r, int val) {
    	for(int i = l; i <= r; i++) a[i] = val;
    	auto bg = split(l), ed = split(r + 1);
    	s.erase(bg, ed);
    	s.insert({l, r, val});
    }
    int rak(int l, int r, int x) {
    	vector<pair<LL, int>> v;
    	auto bg = split(l), ed = split(r + 1);
    	for(auto i = bg; i != ed; i++) 
    		v.push_back({i->v, i->r - i->l + 1});	
    
    	sort(v.begin(), v.end());
    	for(auto it = v.begin(); it != v.end(); it++) {
    		x -= it -> se;
    		if(x <= 0) return it -> fi;
    	}
    	assert(0);
    }
    int fp(int a, int p) {
    	int base = 1; a %= mod;
    	while(p) {
    		if(p & 1) base = 1ll * base * a % mod;
    		a = 1ll * a * a % mod; p >>= 1;
    	}
    	return base;
    }
    int po(int l, int r, int x) {
    	if(l == 6 && r == 7) {
    		puts("G");
    	}
    	auto bg = split(l);
    	printf("%d %d %d %d
    ", bg->l, bg->r, bg->v);
    	auto ed = split(r + 1);
    	int ans = 0;
    	for(sit i = bg; i != ed; i++) {
    		printf("%d %d %d %d
    ", i->l, i->r, i->v);
    		ans = (ans + (i->r - i->l + 1) * fp(i->v, x) % mod) % mod;
    	}
    	return ans;
    }
    signed main() {
    	N = read(); M = read(); seed = read(); vmax = read();
    	for(int i = 1; i <= N; i++) a[i] = (rnd() % vmax) + 1, s.insert({i, i, a[i]});
    	s.insert({N + 1, N + 1, 0});
    	for(int i = 1; i <= M; i++) {
    		int op = (rnd() % 4) + 1; int l = (rnd() % N) + 1; int r = (rnd() % N) + 1, x = -1;
    		if(l > r) swap(l, r);
    		
    		if(op == 3) x = (rnd() % (r - l + 1)) + 1;
    		else x = (rnd() % vmax) + 1;
    		if(op == 4) mod = (rnd() % vmax) + 1; 
    		if(op == 1) Add(l, r, x);
    		else if(op == 2) Mem(l, r, x);
    		else if(op == 3) cout << rak(l, r, x) << '
    ';
    		else cout << po(l, r, x) << '
    ';
    	}
    	return 0;
    }
    /*
    50 50 658073485 946088556
    */
    
  • 相关阅读:
    replace和translate的用法
    java中静态方法和静态类的学习
    rank()函数的使用
    orcle函数的使用,及其调用
    父子级菜单的查询
    Centos7 安装K8S 小记
    三剑客之三 Awk小记
    三剑客之二 Sed小记
    三剑客之一 Grep小记
    ssh与telnet区别 小记
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10357168.html
Copyright © 2020-2023  润新知