QQ music player-JQuery Realization

2022-12-20   ES  

link

  http://www.lydsy.com/JudgeOnline/problem.php?id=2333

The interpretation of the Internet can be piled up together, so powerful, I don’t …
This question can be inspired by merging. Each of the root nodes that are collected to maintain a pile, and then inspire mergers and do it.
Among them, the main maintenance pile we can engage in a modification mark that all the elements in this pile have been added, nothing to say ..
time complexity O(Nlog2N)

code

// Enlightenment merger+pile+and check collection#include <cstdio>
#include <algorithm>
#include <queue>
#define heap priority_queue
#define maxn 300005
using namespace std;
int N, Q, f[maxn], V, d[maxn], a[maxn], vis[maxn];
struct data{
   int id, w;data(int a, int b):id(a),w(b){}data(){}}stack[maxn];
heap<data> h[maxn], big;
bool operator<(const data &a, const data &b){
   return a.w<b.w;}
int find(int x){
   return f[x]==x?x:f[x]=find(f[x]);}
inline void upd(int x)
{
    if(x)while(a[h[x].top().id]^h[x].top().w)h[x].pop();
    else while(h[big.top().id].empty() or
                h[big.top().id].top().w+d[big.top().id]!=big.top().w)big.pop();
}
inline void merge(int x, int y)
{
    int fx=find(x), fy=find(y);
    if(fx==fy)return;
    if(h[fx].size()>h[fy].size())swap(fx,fy);
    for(;!h[fx].empty();h[fx].pop())
        if(h[fx].top().w==a[h[fx].top().id] and vis[h[fx].top().id]!=Q)
            h[fy].push(data(h[fx].top().id,h[fx].top().w+d[fx]-d[fy])),
            a[h[fx].top().id]+=d[fx]-d[fy], vis[h[fx].top().id]=Q;
    f[fx]=fy;
    upd(fy);
    big.push(data(fy,h[fy].top().w+d[fy]));
    upd(0);
}
inline int read(int x=0)
{
    char c=getchar(); bool f=0;
    while(c<48 or c>57)f=f or c=='-', c=getchar();
    while(c>=48 and c<=57)x=(x<<1)+(x<<3)+c-48, c=getchar();
    return f?-x:x;
}
int main()
{
    char type[5]; int x, v, i, fx;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
        scanf("%d",a+i), f[i]=i, h[i].push(data(i,a[i])), big.push(data(i,a[i]));
    scanf("%d",&Q);
    for(Q++;Q^1;Q--)
    {
        scanf("%s",type);
        if(*type=='U')x=read(), v=read(), merge(x,v);
        if(*type=='A')
        {
            if(type[1]=='1')
            {
                x=read(), v=read();
                a[x]+=v;
                h[fx=find(x)].push(data(x,a[x]));
                upd(fx);
                big.push(data(fx,h[fx].top().w+d[fx]));
                upd(0);
            }
            if(type[1]=='2')
            {
                x=read(), v=read();
                d[fx=find(x)]+=v;
                big.push(data(fx,h[fx].top().w+d[fx]));
                upd(0);
            }
            if(type[1]=='3')d[0]+=read();
        }
        if(*type=='F')
        {
            if(type[1]=='1')
                x=read(), printf("%d\n",a[x]+d[find(x)]+d[0]);
            if(type[1]=='2')
                x=read(), printf("%d\n",h[find(x)].top().w+d[find(x)]+d[0]);
            if(type[1]=='3')
                printf("%d\n",big.top().w+d[0]);
        }
    }
    return 0;
}

source

Related Posts

Blind webhooks

Redis Error: Waiting for Redis to Shutdown … (Can’t close Redis)

R language Clear variable/clear all variables/clean up memory/screen, finally remember to use GC () again

computer composition -Verilog flow lamp experiment

QQ music player-JQuery Realization

Random Posts

Customized radio Sunshine of Radio Receptions

echarts overlap column -shaped chart + display%

Caddy & GRPC (3) Add a reverse proxy plug -in to Caddy

Steam how to convert the district service (take PES2021 as an example)

Redis Error: Waiting for Redis to Shutdown … (Can’t close Redis)