CF896C Willem, Chtholly and Seniorious

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define IT set<node>::iterator
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m, sum;
struct node
{
    int l, r; 
    mutable LL v; 
    node(int L, int R = -1, LL V = 0):l(L), r(R), v(V) {}
    bool operator<(const node& o) const {
        return l < o.l;
    }
};
set<node> s;
IT split(int pos)
{
    IT it = s.lower_bound(node(pos));   
    if (it != s.end() && it->l == pos)   
        return it;
    -- it;  
    int L = it->l, R = it->r;  
    LL V = it->v;  
    s.erase(it);   
    s.insert(node(L, pos-1, V));  
    return s.insert(node(pos, R, V)).first;  
}
void assign_val(int l, int r, LL val)
{
    IT itr = split(r+1), itl = split(l);  
    
    s.erase(itl, itr);  
    s.insert(node(l, r, val));  
}
void add(int l, int r, LL val)
{
    IT itr = split(r+1), itl = split(l);  
    for (; itl != itr; ++ itl) 
        itl->v += val;
}
LL ranks(int l, int r, int k)
{
    vector<pair<LL, int>> vp;
    IT itr = split(r+1), itl = split(l);  
    vp.clear();
    for (; itl != itr; ++itl)
        vp.push_back(pair<LL,int>(itl->v, itl->r - itl->l + 1));
    sort(vp.begin(), vp.end());
    for (vector<pair<LL,int> >::iterator it=vp.begin();it!=vp.end();++it)
    {
        k -= it->second;
        if (k <= 0) 
            return it->first;
    }
}
LL pown(LL a, LL b, LL mod)
{
    LL res = 1;
    LL ans = a % mod;
    while (b)
    {
        if (b&1) 
            res = res * ans % mod;
        ans = ans * ans % mod;
        b>>=1;
    }
    return res;
}

LL sum(int l, int r, int ex, int mod)
{
    IT itl = split(l),itr = split(r+1);
    LL res = 0;
    for (; itl != itr; ++itl)
        res = (res + (LL)(itl->r - itl->l + 1) * pown(itl->v, LL(ex), LL(mod))) % mod;
    return res;
}
int main() {
	IOS;
	cin >> n >> m;
	s.insert(1, n, 1);
	for (int i = 1; i <= m; i ++ ) {
		int l, r, op;
		cin >> l >> r >> op;
		if (op == 1)	assign_val(l, r, 0);
		else	assign_val(l, r, 1);
		cout << sum << endl;
	}
 	return 0;
}
posted @ 2022-03-04 23:38  Angels_of_Death  阅读(32)  评论(0)    收藏  举报