Submission #278749

# Submission time Handle Problem Language Result Execution time Memory
278749 2020-08-21T18:07:38 Z shinjan Horses (IOI15_horses) C++14
17 / 100
58 ms 41848 KB
#include <iostream>
#include <bits/stdc++.h>
#define maxN 500001
#define mod 1000000007
#include "horses.h"
using namespace std;
long long drvo[4*maxN];
long long mlazy[4*maxN];
long long dlazy[4*maxN];
int x[maxN];
int y[maxN];
int n;
pair<int,int> range[4*maxN];
int st=1;
void lenja(int node,int pos,int val,int prev)
{
    if(mlazy[node]!=1 || dlazy[node]!=1)
    {
        drvo[node]=(drvo[node]/dlazy[node])*mlazy[node];
        if(node<st)
        {
            mlazy[2*node]*=mlazy[node];
            mlazy[2*node+1]*=mlazy[node];
            dlazy[2*node]*=dlazy[node];
            dlazy[2*node+1]*=dlazy[node];
        }
        mlazy[node]=1;
        dlazy[node]=1;
    }
    //cout<<"cvor: "<<node<<"range:"<<range[node].first<<" "<<range[node].second<<endl;
    if(range[node].second<pos)
        return;
    if(range[node].first>=pos)
    {
        //cout<<"upada ceo"<<endl;
        drvo[node]=(drvo[node]/prev)*val;
        if(node<st)
        {
            mlazy[2*node]*=val;
            mlazy[2*node+1]*=val;
            dlazy[2*node]*=prev;
            dlazy[2*node+1]*=prev;
        }
        return;
    }
    lenja(2*node,pos,val,prev);
    lenja(2*node+1,pos,val,prev);
    drvo[node]=max(drvo[2*node],drvo[2*node+1]);
}
int init(int sz,int newx[],int newy[])
{
    n=sz;
    for(int i=0;i<n;i++)
    {
        x[i]=newx[i];
        y[i]=newy[i];
    }
    while(st<n)
    {
        st*=2;
    }
    long long currx=1;
    for(int i=0;i+st<2*st;i++)
    {
        if(i<n)
        {
            currx*=x[i];
            drvo[i+st]=(y[i]*currx);
        }
        else{
            drvo[i]=0;
        }
        range[i+st].first=i;
        range[i+st].second=i;
        mlazy[i+st]=1;
        dlazy[i+st]=1;
    }
    for(int i=st-1;i>=1;i--)
    {
        drvo[i]=max(drvo[2*i],drvo[2*i+1]);
        range[i].first=range[2*i].first;
        range[i].second=range[2*i+1].second;
        mlazy[i]=1;
        dlazy[i]=1;
    }
    long long ans=drvo[1];
    ans=ans%mod;
    return ans;
}
void menjajX(int pos,int val,int prev)
{
    //cout<<"menjam x na poz:"<<pos<<" prethodni"<<prev<<endl;
    pos=pos+st;
    drvo[pos]=((drvo[pos]/prev)*val);
    pos=pos/2;
    while(pos>=1)
    {
        drvo[pos]=max(drvo[2*pos],drvo[2*pos+1]);
        pos=pos/2;
    }
}
int updateY(int pos,int val)
{
    int prev=y[pos];
    y[pos]=val;
    pos=pos+st;
    drvo[pos]=((drvo[pos]/prev)*val);
    pos=pos/2;
    while(pos>=1)
    {
        drvo[pos]=max(drvo[2*pos],drvo[2*pos+1]);
        pos=pos/2;
    }
    long long ans=drvo[1];
    ans=ans%mod;
    return ans;
}
int updateX(int pos,int val)
{
    int prev=x[pos];
    for(int i=pos;i<n;i++)
    {
        menjajX(i,val,prev);
    }
    x[pos]=val;
    long long ans=drvo[1];
    ans=ans%mod;
    return ans;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:88:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   88 |     return ans;
      |            ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:116:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  116 |     return ans;
      |            ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:128:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  128 |     return ans;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Incorrect 0 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 41848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Incorrect 0 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Incorrect 1 ms 384 KB Output isn't correct
22 Halted 0 ms 0 KB -