P1016 budget simulation greed of travelers

Title Description

Mo Mo has purchased a set of N color brushes (some of them may be the same color), which are arranged in a row. You need to answer Mo Mo's questions. Mo Mo will issue the following instructions to you:

1. The Q L R representative asks you how many different colors there are from the L brush to the R brush.

2. R P Col replaces the p-th brush with the color Col.

Do you know what you need to do to meet the requirements of ink?

I / O format

Input format:


The first line contains two integers, N and M, representing the number of initial brushes and the number of things that ink will do.

N integers in the second row represent the color of the i-th brush in the initial brush row.

From line 3 to line 2+M, each line represents one thing that ink will do. For the format, see the title stem.


Output format:


For each Query query, you need to give a number in the corresponding line, representing that there are several different colors of brushes from the L-th brush to the R-th brush.


Example of input and output

Input sample × 1:copy
6 5
1 2 3 4 5 5
Q 1 4
Q 2 6
R 1 2
Q 1 4
Q 2 6
Output samplecopy

A more troublesome simulation problem:
Greedy principle:
If there is a gas station with a lower oil price within the scope of the current service station, maintain the current oil volume to exactly that smaller service station
If not, top up
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define pb push_back
#define CLR(A,v)  memset(A,v,sizeof A)
#define inf 0x3f3f3f3f
#define lson l,m,pos<<1
#define rson m+1,r,pos<<1|1
const int N=3e6+5;
struct node
    double p,d;
double D,C,money,D2,p1,nowoil;
int nowpos,n;

int main()


    double maxx=0;
    if(C*D2<maxx){cout<<"No Solution"<<endl;return 0;}

        int flag=-1;

        if(flag!=-1){ double dis=s[flag].d-s[nowpos].d;double x=dis/D2-nowoil;if(x<0){nowoil-=dis/D2;nowpos=flag;continue;} money+=x*s[nowpos].p; nowoil=0;nowpos=flag;continue;}

        if(s[n+1].d-s[nowpos].d<=C*D2){ double dis=s[n+1].d-s[nowpos].d; double x=dis/D2-nowoil; money+=x*s[nowpos].p;break;  }//If you can jump to the end

        double x=C-nowoil;  money+=s[nowpos].p*x;  nowoil=C-(s[nowpos+1].d-s[nowpos].d)/D2;  nowpos++;//If the current position of the oil price is the smallest


    return 0;


Tags: OS X

Posted on Mon, 04 Nov 2019 13:13:52 -0500 by aa-true-vicious