Submission #461171

# Submission time Handle Problem Language Result Execution time Memory
461171 2021-08-09T13:04:55 Z zaneyu Horses (IOI15_horses) C++14
100 / 100
1071 ms 31276 KB
/*input
3 
2 1 3
3 4 1
1
2 1 2
*/
#include "horses.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const ll INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const int maxn=5e5+5;
const ll maxlg=__lg(maxn)+2;
int val[4*maxn],md[4*maxn];
inline void mdf(int idx,int l,int r,int p,int x){
    if(l==r){
        val[idx]=md[idx]=x;
        return;
    }
    int mid=(l+r)>>1;
    if(p<=mid){
        mdf(idx<<1,l,mid,p,x);
    }
    else{
        mdf(idx<<1|1,mid+1,r,p,x);
    }
    val[idx]=min((ll)INF,(ll)val[idx<<1]*val[idx<<1|1]);
    md[idx]=mult(md[idx<<1],md[idx<<1|1]);
}
inline int qv(int idx,int l,int r,int ql,int qr){
    if(ql>qr) return 1;
    if(ql<=l and r<=qr) return val[idx];
    int mid=(l+r)>>1;
    if(qr<=mid) return qv(idx<<1,l,mid,ql,qr);
    if(ql>mid) return qv(idx<<1|1,mid+1,r,ql,qr);
    return min((ll)INF,(ll)qv(idx<<1,l,mid,ql,qr)*qv(idx<<1|1,mid+1,r,ql,qr));
}
inline int qm(int idx,int l,int r,int ql,int qr){
    if(ql>qr) return 1;
    if(ql<=l and r<=qr) return md[idx];
    int mid=(l+r)>>1;
    if(qr<=mid) return qm(idx<<1,l,mid,ql,qr);
    if(ql>mid) return qm(idx<<1|1,mid+1,r,ql,qr);
    return mult(qm(idx<<1,l,mid,ql,qr),qm(idx<<1|1,mid+1,r,ql,qr)); 
}
int opt[4*maxn];
int y[maxn],n;
void build(int idx,int l,int r){
    if(l==r){
        opt[idx]=l;
        return;
    }
    int mid=(l+r)>>1;
    build(idx<<1,l,mid);
    build(idx<<1|1,mid+1,r);
}
void upd(int idx,int l,int r,int p){
    if(l==r){
        return;
    }
    int mid=(l+r)>>1;
    if(p<=mid){
        upd(idx<<1,l,mid,p);
    }
    else{
        upd(idx<<1|1,mid+1,r,p);
    }
    if(y[opt[idx<<1|1]]*(ll)qv(1,0,n-1,opt[idx<<1]+1,opt[idx<<1|1])>=y[opt[idx<<1]]) opt[idx]=opt[idx<<1|1];
    else opt[idx]=opt[idx<<1];
}
int init(int N, int X[], int Y[]) {
    n=N;
    REP(i,n) mdf(1,0,n-1,i,X[i]);
    build(1,0,n-1);
    REP(i,n) y[i]=Y[i],upd(1,0,n-1,i);
    return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}

int updateX(int pos, int val) { 
    mdf(1,0,n-1,pos,val);
    upd(1,0,n-1,pos);
    return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}

int updateY(int pos, int val) {
    y[pos]=val;
    upd(1,0,n-1,pos);
    return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
}

Compilation message

horses.cpp: In function 'void mdf(int, int, int, int, int)':
horses.cpp:72:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   72 |     val[idx]=min((ll)INF,(ll)val[idx<<1]*val[idx<<1|1]);
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:73:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   73 |     md[idx]=mult(md[idx<<1],md[idx<<1|1]);
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qv(int, int, int, int, int)':
horses.cpp:81:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |     return min((ll)INF,(ll)qv(idx<<1,l,mid,ql,qr)*qv(idx<<1|1,mid+1,r,ql,qr));
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int qm(int, int, int, int, int)':
horses.cpp:89:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   89 |     return mult(qm(idx<<1,l,mid,ql,qr),qm(idx<<1|1,mid+1,r,ql,qr));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:121:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  121 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:124:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  124 | int updateX(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
   59 | int val[4*maxn],md[4*maxn];
      |     ^~~
horses.cpp:127:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  127 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:130:26: warning: declaration of 'val' shadows a global declaration [-Wshadow]
  130 | int updateY(int pos, int val) {
      |                      ~~~~^~~
horses.cpp:59:5: note: shadowed declaration is here
   59 | int val[4*maxn],md[4*maxn];
      |     ^~~
horses.cpp:133:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  133 |     return mult(y[opt[1]],qm(1,0,n-1,0,opt[1]));
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 19484 KB Output is correct
2 Correct 527 ms 19440 KB Output is correct
3 Correct 581 ms 19444 KB Output is correct
4 Correct 844 ms 19572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 342 ms 18484 KB Output is correct
34 Correct 679 ms 18660 KB Output is correct
35 Correct 331 ms 18640 KB Output is correct
36 Correct 319 ms 18512 KB Output is correct
37 Correct 311 ms 18568 KB Output is correct
38 Correct 603 ms 18508 KB Output is correct
39 Correct 290 ms 18500 KB Output is correct
40 Correct 308 ms 18680 KB Output is correct
41 Correct 293 ms 18628 KB Output is correct
42 Correct 296 ms 18656 KB Output is correct
43 Correct 302 ms 18456 KB Output is correct
44 Correct 303 ms 18448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 452 ms 19428 KB Output is correct
34 Correct 523 ms 19476 KB Output is correct
35 Correct 570 ms 19424 KB Output is correct
36 Correct 866 ms 19520 KB Output is correct
37 Correct 344 ms 18556 KB Output is correct
38 Correct 675 ms 18584 KB Output is correct
39 Correct 345 ms 18632 KB Output is correct
40 Correct 329 ms 18480 KB Output is correct
41 Correct 307 ms 18580 KB Output is correct
42 Correct 614 ms 18580 KB Output is correct
43 Correct 296 ms 18504 KB Output is correct
44 Correct 308 ms 18512 KB Output is correct
45 Correct 295 ms 18500 KB Output is correct
46 Correct 301 ms 18504 KB Output is correct
47 Correct 293 ms 18500 KB Output is correct
48 Correct 295 ms 18440 KB Output is correct
49 Correct 728 ms 19464 KB Output is correct
50 Correct 1071 ms 19404 KB Output is correct
51 Correct 516 ms 31276 KB Output is correct
52 Correct 417 ms 30804 KB Output is correct
53 Correct 592 ms 22876 KB Output is correct
54 Correct 798 ms 23492 KB Output is correct
55 Correct 382 ms 21572 KB Output is correct
56 Correct 403 ms 26384 KB Output is correct
57 Correct 474 ms 22384 KB Output is correct
58 Correct 411 ms 22780 KB Output is correct
59 Correct 293 ms 24832 KB Output is correct