답안 #781478

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781478 2023-07-13T06:52:41 Z vjudge1 말 (IOI15_horses) C++17
컴파일 오류
0 ms 0 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+37;; 
#define ll long long int
set<int> px; // not 1 x positions
ll st[2][N*4]; // st[0] returns multipication, st[1] returns max,
int mod = 1e9+7, n;
vector<int> x, y;

void f(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}
int m(ll a){
    return a%mod;
}

void update(int v, int l, int r, int pos, int val, int t){
    if(l==r) st[t][v] = val;
    else if(l<r){
        int mid = (r+l) / 2;
        if(pos <= mid) update(v*2, l, mid, pos, val, t);
        else update(v*2+1, mid+1, r, pos, val, t);

        if(t == 0) st[t][v] = m(st[t][v*2]*st[t][v*2+1]);
        else st[t][v] = max (st[t][v*2], st[t][v*2+1]);
    }
}

int get(int v, int l, int r, int tl, int tr, int t){
    if(l>r || tl > r || l > tr){
        if(t == 0) return 1;
        else return 0;
    }
    else if(l>=tl && r <= tr) return st[t][v];
    else{
        int mid = (r+l) / 2;
       
        if(t == 0) return m(get(v*2, l, mid, tl, tr, t)*get(v*2+1, mid+1, r, tl, tr, t));
        return max (get(v*2, l, mid, tl, tr, t), get(v*2+1, mid+1, r, tl, tr, t));
    }
}

int ans(){
    vector<array<ll, 2>> a;

    for(int i=0; i<n; i++){
        a.push_back({i, y[i]});
    }

//    return m(ma);
    //int r=n-1;
    ll mx=1, my;

  /*  for(auto i: px){
        int pos=-i;
        mx*=x[pos];
        if(mx>(ll)1e9) break;
        a.push_back({pos, get(1, 0, n-1, pos, r, 1)});
        r=pos-1;
    }

    if(!px.size()){
        return get(1, 0, n-1, 0, n-1, 1);
    }*/
    ll k = (a.size()==1?1:x[a[1][0]]);

    mx = a[0][0], my=a[0][1];
    for(int i=1; i<a.size(); i++){
        if(a[i][1]*k >= my){
            my=a[i][1];;
            mx=a[i][0];
            k=(i+1<a.size()?a[i+1][1]:1);
        }
        else{
            k=m(k*(i+1<a.size()?a[i+1][1]:1));
        }
    }
    int t=1;

    for(int i=0; i<=mx; i++) t*=x[i];
    return m(t*my);
}

int init(int N, int X[], int Y[]) {
    n=N;

    x.resize(n); y.resize(n);
    for(int i = 0; i < 4*n+37; i++){
        st[0][i] = 1;
    }

    for(int i = 0; i < n; i++){
        x[i] = X[i]; y[i] = Y[i];
    }

    for(int i = 0; i < n; i++){
        if(x[i] != 1) px.insert(-i), update(1, 0, n-1, i, x[i], 0);
        update(1, 0, n-1, i, y[i], 1);
    } 

    return ans();
}

int updateX(int pos, int val) { 

    x[pos] = val;
    if(x[pos] > 1 && val == 1){
        px.erase(-pos);
    }
    else if(x[pos] == 1 && val > 1){
        px.insert(-pos);
    }
    update(1, 0, n-1, pos, val, 0);

    return ans();
}

int updateY(int pos, int val) {
    y[pos] = val;
    update(1, 0, n-1, pos, val, 1);
    return ans();
}

int main() {
    f();

    int N; cin >> N; 

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}

	for (int i = 0; i < N; i++) {
		cin >> Y[i];
	}	
    ll f= 1e18; //cout<<f;

    cout<<init(N,X,Y)<<"\n";

	int M; cin >> M;

	for (int i = 0; i < M; i++) {
		int type, pos , val; cin >> type >> pos >> val;

		if (type == 1) {
			cout<<updateX(pos,val)<<"\n";
		} else if (type == 2) {
			cout<<updateY(pos,val)<<"\n";
		}
	}

	return 0;
}

Compilation message

horses.cpp: In function 'int m(long long int)':
horses.cpp:16:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   16 |     return a%mod;
      |            ~^~~~
horses.cpp: In function 'int get(int, int, int, int, int, int)':
horses.cpp:36:45: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   36 |     else if(l>=tl && r <= tr) return st[t][v];
      |                                      ~~~~~~~^
horses.cpp: In function 'int ans()':
horses.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=1; i<a.size(); i++){
      |                  ~^~~~~~~~~
horses.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             k=(i+1<a.size()?a[i+1][1]:1);
      |                ~~~^~~~~~~~~
horses.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             k=m(k*(i+1<a.size()?a[i+1][1]:1));
      |                    ~~~^~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:86:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   86 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:4:11: note: shadowed declaration is here
    4 | const int N = 5e5+37;;
      |           ^
horses.cpp: In function 'int main()':
horses.cpp:129:9: warning: declaration of 'N' shadows a global declaration [-Wshadow]
  129 |     int N; cin >> N;
      |         ^
horses.cpp:4:11: note: shadowed declaration is here
    4 | const int N = 5e5+37;;
      |           ^
horses.cpp:141:8: warning: unused variable 'f' [-Wunused-variable]
  141 |     ll f= 1e18; //cout<<f;
      |        ^
horses.cpp: In function 'void f()':
horses.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
horses.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccr2fNxt.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6JRynt.o:horses.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status