Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define Nmax 300000
- #define BUF 16384
- using namespace std;
- class InParser {
- private:
- FILE *fin;
- char *buff;
- int sp;
- char read_ch() {
- ++sp;
- if (sp == BUF) {
- sp = 0;
- fread(buff, 1, BUF, fin);
- }
- return buff[sp];
- }
- public:
- InParser(const char* nume) {
- fin = fopen(nume, "r");
- buff = new char[BUF]();
- sp = BUF-1;
- }
- InParser& operator >> (int &n) {
- char c;
- while (!isdigit(c = read_ch()) && c != '-');
- int sgn = 1;
- if (c == '-') {
- n = 0;
- sgn = -1;
- } else {
- n = c - '0';
- }
- while (isdigit(c = read_ch())) {
- n = 10 * n + c - '0';
- }
- n *= sgn;
- return *this;
- }
- InParser& operator >> (long long &n) {
- char c;
- n = 0;
- while (!isdigit(c = read_ch()) && c != '-');
- long long sgn = 1;
- if (c == '-') {
- n = 0;
- sgn = -1;
- } else {
- n = c - '0';
- }
- while (isdigit(c = read_ch())) {
- n = 10 * n + c - '0';
- }
- n *= sgn;
- return *this;
- }
- };
- using namespace std;
- class OutParser {
- private:
- FILE *fout;
- char *buff;
- int sp;
- void write_ch(char ch) {
- if (sp == 50000) {
- fwrite(buff, 1, 50000, fout);
- sp = 0;
- buff[sp++] = ch;
- } else {
- buff[sp++] = ch;
- }
- }
- public:
- OutParser(const char* name) {
- fout = fopen(name, "w");
- buff = new char[50000]();
- sp = 0;
- }
- ~OutParser() {
- fwrite(buff, 1, sp, fout);
- fclose(fout);
- }
- OutParser& operator << (int vu32) {
- if (vu32 <= 9) {
- write_ch(vu32 + '0');
- } else {
- (*this) << (vu32 / 10);
- write_ch(vu32 % 10 + '0');
- }
- return *this;
- }
- OutParser& operator << (long long vu64) {
- if (vu64 <= 9) {
- write_ch(vu64 + '0');
- } else {
- (*this) << (vu64 / 10);
- write_ch(vu64 % 10 + '0');
- }
- return *this;
- }
- OutParser& operator << (char ch) {
- write_ch(ch);
- return *this;
- }
- OutParser& operator << (const char *ch) {
- while (*ch) {
- write_ch(*ch);
- ++ch;
- }
- return *this;
- }
- };
- InParser f("bogdan.in");
- OutParser g("bogdan.out");
- bool Corect;
- int n,v[Nmax],pos,valoare,a,b,Maxim;
- struct arbore_intervale
- {
- int val;
- bool cresc;
- }arb[Nmax];
- void creare(int nod,int st,int dr)
- {
- if (st==dr)
- {
- f>>arb[nod].val;
- v[st]=arb[nod].val;
- arb[nod].cresc=true;
- }
- else
- {
- int mij=(st+dr)/2;
- creare(2*nod,st,mij);
- creare(2*nod+1,mij+1,dr);
- if(v[mij]<=v[mij+1]&&arb[2*nod].cresc==1&&arb[2*nod+1].cresc==1)
- {
- arb[nod].cresc=true;
- }
- else
- {
- arb[nod].cresc=false;
- }
- }
- }
- void citire()
- {
- f>>n;
- creare(1,1,n);
- }
- void adauga(int nod,int st,int dr)
- {
- if(st==dr)
- {
- arb[nod].val=valoare;
- }
- else
- {
- int mij=(st+dr)/2;
- if(pos<=mij)
- {
- adauga(2*nod,st,mij);
- }
- else
- {
- adauga(2*nod+1,mij+1,dr);
- }
- if(arb[2*nod].cresc==true&&arb[2*nod+1].cresc==true&&v[mij]<=v[mij+1])
- {
- arb[nod].cresc=1;
- }
- else
- {
- arb[nod].cresc=0;
- }
- }
- }
- void verificare(int nod,int st,int dr)
- {
- if(a<=st&&dr<=b)
- {
- if(arb[nod].cresc==0||(Maxim>v[st]))
- {
- Corect=false;
- }
- else
- {
- Maxim=v[dr];
- }
- }
- else
- if(Corect==true)
- {
- int mij=(st+dr)/2;
- if(a<=mij)
- {
- verificare(2*nod,st,mij);
- }
- if(mij+1<=b&&Corect)
- {
- verificare(2*nod+1,mij+1,dr);
- }
- }
- }
- void rez()
- {
- int Numar_Teste,Tip_Test;
- f>>Numar_Teste;
- for(int i=1;i<=Numar_Teste;i++)
- {
- f>>Tip_Test;
- if(Tip_Test==1)
- {
- f>>pos>>valoare;
- v[pos]=valoare;
- adauga(1,1,n);
- }
- else
- {
- f>>a>>b;
- Corect=true;
- Maxim=v[a];
- verificare(1,1,n);
- if(Corect==true)
- g<<"DA"<<'\n';
- else
- g<<"NU"<<'\n';
- }
- }
- }
- int main()
- {
- citire();
- rez();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement