set terminal pngcairo size 800,1000 font "Arial,12"
set output 'result.png'
set encoding utf8

set grid xtics ytics ls 1 lc rgb "#bbbbbb" lw 1 dt 2
set xlabel "Количество элементов в массиве, тыс" offset 0,-1
set ylabel "Время выполнения, тики процессора" offset 1,0

set xtics rotate by 90 right

set multiplot layout 2,1

# График 1: Все алгоритмы (Log Scale)
set title "Общая сложность (Log scale)"
set logscale y 10
set format y "%.0f"
set key top left box opaque

set xrange [250:5000]
set xtics 250

plot 'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):2 with lp pt 9 ps 1 lw 2 lc rgb "red" title "Linear", \
     'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):3 with lp pt 7 ps 1 lw 2 lc rgb "blue" title "Binary", \
     'table1.dat' using ($1 >= 250000 ? $1/1000 : 1/0):4 with lp pt 5 ps 1 lw 2 lc rgb "#00CC00" title "Exponential"

# График 2: Binary vs Exponential (Linear Scale)
unset logscale y
set title "Детальное сравнение: Binary vs Exponential"
set format y "%.0f"
set key top left box opaque

set xrange [5:100]
set xtics 5

plot 'table1.dat' using ($1 < 250000 ? $1/1000 : 1/0):3 with lp pt 9 ps 1.5 lw 2 lc rgb "red" title "Binary", \
     'table1.dat' using ($1 < 250000 ? $1/1000 : 1/0):4 with lp pt 7 ps 1.5 lw 2 lc rgb "blue" title "Exponential"

unset multiplot
